[deleted]
Thanks for your feedback. I created the library simply because it just fits my use cases better. I have used encoding/json quite a lot, and for instance, I think golang's strict types makes it inconvenient to dig through arbitrary maps in a quick way. That's what the Get-method in Jason is trying to solve. Similar to how bitly/go-simplejson does it, but with some fine tuning.
Show HN: Jason – A new JSON Library for Go
11–20 of 55 posts
Re: Show HN: Jason – A new JSON Library for Go
#12This 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 (I see these as complimenta…
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.
Re: Show HN: Jason – A new JSON Library for Go
#13For anyone wondering why this is necessary, as some others in this thread have mentioned, the standard go way to deserialize json is to pass a pointer to a struct, and the system will "fill" it with the json. There is no easy way to sort of "parse" json piece by piece, which is what this library provides
Well, you can use json.RawMessage to delay decoding until other values are known[0].
However, this still requires that the input set is known at compile-time, which may not always be the case (some APIs sadly use a highly variable JSON schema, which can only be determined at runtime.)
You also don't need to pass a pointer to a struct. For example, you can pass an interface{}, which allows you to decode data into a type that is specified by the calling function, which I made heavy use of in this Twitter client library, for example[1].
(This is more or less how encoding/json itself works under the surface, when you think about it, but oftentimes people forget to take advantage of this idiom in practice.)
[0] http://golang.org/pkg/encoding/json/#RawMessage
[1] https://github.com/ChimeraCoder/anaconda/blob/master/users.g...
Re: Show HN: Jason – A new JSON Library for Go
#14[deleted]
Re: Show HN: Jason – A new JSON Library for Go
#15Earlier quoted context omitted.
Thanks for your feedback. I created the library simply because it just fits my use cases better. I have used encoding/json quite a lot, and for instance, I think golang's strict types makes it inconvenient to dig through arbitrary maps in a quick way. That's what the Get-method in Jason is trying to solve. Similar to how bitly/go-simplejson does it, but with some fine tuning.
Speaking of the .Get method, wouldn't returning an error alongside the value instead of just the default object be more idiomatic?
Re: Show HN: Jason – A new JSON Library for Go
#16I would stray away from making the library name too similar in phonetic sound to the data it's meant to process. There was already enough confusion in an office I worked at with a non-developer whose name was "Jason"
Re: Show HN: Jason – A new JSON Library for Go
#17I would stray away from making the library name too similar in phonetic sound to the data it's meant to process. There was already enough confusion in an office I worked at with a non-developer whose name was "Jason"
Re: Show HN: Jason – A new JSON Library for Go
#18For anyone wondering why this is necessary, as some others in this thread have mentioned, the standard go way to deserialize json is to pass a pointer to a struct, and the system will "fill" it with the json. There is no easy way to sort of "parse" json piece by piece, which is what this library provides
You mean like this? http://play.golang.org/p/mMh7HGuTbe
Re: Show HN: Jason – A new JSON Library for Go
#19For anyone wondering why this is necessary, as some others in this thread have mentioned, the standard go way to deserialize json is to pass a pointer to a struct, and the system will "fill" it with the json. There is no easy way to sort of "parse" json piece by piece, which is what this library provides
Re: Show HN: Jason – A new JSON Library for Go
#20Here's an example: http://play.golang.org/p/jrqBcPuQei