by zachgersh · 11y ago · 0 comments
type JSON map[string]interface{}
Go ahead and use the json.RawMessage type instead:
http://golang.org/pkg/encoding/json/#RawMessage
Not even going to wade into the lack of generics war, still very happy without them and going on a full year of Go usage.
If it doesn't, then you just use json.RawMessage to defer unmarshalling, but you can still dispatch to a finite number of structs that represent the universe of possible responses.
[0] And no need to write it all out by hand - if you have a single example JSON response, you can generate it automatically: https://github.com/ChimeraCoder/gojson