5 ms·
var res map[string]any err := json.Unmarshal(&res)
by kloop 2y ago
var res map[string]any
err := json.Unmarshal(&res)
- scubbo 2y agoUh huh....and what comes next? Trying to descend more than a couple of layers into a GoLang JSON object is a mess of casts.
- Yoric 2y agoEspecially when you're not certain of the type used for numbers.
- lenkite 2y agoWell, one used to have https://github.com/mitchellh/mapstructure https://github.com/mitchellh/mapstructure which assisted here, but the lib then got abandoned.
- jen20 2y agoBlessed fork: https://github.com/go-viper/mapstructure https://github.com/go-viper/mapstructure
- kloop 2y agoThe same things that happens in JS or python. If you get a key wrong it throws (panics in go)
- scubbo 2y agoI wasn't talking about getting the keys wrong, but rather the insane verbosity of GoLang - `myVariable := retrievedObject.(map[string]interface{})["firstLevelKey"].(map[string]interface{})["secondLevelKey"].(string)` vs. `myVariable = retrievedObject["firstLevelKey"]["secondLevelKey"]` "Oh, but that's just how it is in strongly-typed languages" - that may well be true, but we're comparing "JS or python" with GoLang here.