8

I really am not a fan of the contortions you have to go through in Golang to deserialize a fucking JSON blob. If this were any other language I would have already had a data structure I could query rather than wasting hours twiddling structs that will be filled properly.

Comments
  • 1
    Are you using the json field tags? Adding optional to those tags might help. I'm also a fan of using the easyjson library, I think it makes json a little nicer in go (and quicker since it gets rid of a bunch of reflection code). Another option is ffjson.
  • 1
    j := map[string]interface{}
    json.Unmarshall(j)

    Profit.
  • 1
    @azous I’ll give that library a try. The difficulty comes in if you don’t know for certain what kind of data you’ll be getting in advance. The processing then becomes this tedious dance of type checks and case statements.
  • 1
    @Karunamon
    That is stdlib 😛
  • 1
    @azous doh- replied to the wrong person.

    Shoving them all in an interface doesn’t save much time because you still cant use the data until you’ve typed the fields.

    Or at least that’s how it looks from the 50 google searches I did yesterday :P
  • 1
    @Karunamon i think you can iterate throught it, not sure, gonna check later
  • 2
    @Karunamon yep, you were right, without a proper unmarshalling it converts everything to string by default, using the map[string]interface{} type
Add Comment