4 ms·
This looks like a good approach to dealing with heterogeneous JSON! (ie, JSON that has an unknown and/or variable structure.) I've always found encoding/json a
by chimeracoder 12y ago
This looks like a good approach to dealing with heterogeneous JSON! (ie, JSON that has an unknown and/or variable structure.) I've always found encoding/json a little clunky for this.
Shameless but relevant plug - if you do know the structure of your JSON in advance, I wrote a tool for automatically generating the appropriate struct definition for it: https://github.com/ChimeraCoder/gojson https://github.com/ChimeraCoder/gojson
(I see these as complimentary tools, rather than conflicting or competing, since they would have two different use cases).
- endymi0n 12y agoThis. If your main use case is JSON as a serialized representation of the ever same object (plus or minus a few optional fields), encoding/json is by far the fastest and most typesafe way to go. (edit: Protip - for the really really fastest way to demarshal JSON, look here https://github.com/pquerna/ffjson https://github.com/pquerna/ffjson for some reflection-free extra speed after your code has settled down) But if your objects can be heterogenous for whatever reasons (think third-party systems, different languages, legacy stacks...) or you're dealing with different kinds of objects landing on the same controller, jason is the perfect complimentary device to deal with more dynamic structures. I've long sought for something like this, thanks to the OP!
- mholt 12y ago(Another plug here) I did too! Except it runs in the browser: https://mholt.github.io/json-to-go https://mholt.github.io/json-to-go And I agree with you about the complementary aspect. Sometimes you can't control the fact that your JSON will have a widely varying structure... but when you can, these generators are nice.
- anonfunction 12y agoGreat tool!
- antonholmquist 12y agoSeems very handy! Thank you