

Show HN: Jason – A new JSON Library for Go - antonholmquist
https://github.com/antonholmquist/jason

======
chimeracoder
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).

~~~
mholt
(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.

~~~
antonholmquist
Seems very handy! Thank you

------
anonfunction
I would say the most idiomatic way is having defined structs and using
encoding/json. Even when you don't know the json schema in advance you can
still parse it into an interface{}.

Here's an example:
[http://play.golang.org/p/jrqBcPuQei](http://play.golang.org/p/jrqBcPuQei)

~~~
Igglyboo
It's definitely safer, but it's a living hell having to define a class for
each possible json structure in Java with gson.

~~~
anonfunction
Not sure where Java came into the conversation but I found a service[1] which
I find really helpful for generating Golang structs from JSON. There is also a
CLI tool[2] that does the same.

[1][http://mholt.github.io/json-to-go/](http://mholt.github.io/json-to-go/)

[2][https://github.com/ChimeraCoder/gojson](https://github.com/ChimeraCoder/gojson)

~~~
eikenberry
Another one.

[https://github.com/str1ngs/jflect](https://github.com/str1ngs/jflect)

------
jamieomatthews
For 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

~~~
rudolf0
>For 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

I sometimes have trouble understanding Go. It kind of seems to retain a lot of
the bad parts of C in terms of developer-friendliness, while still being
relatively slower than C and garbage-collected.

~~~
enneff
What are you having trouble with in this instance? Pointers and structs? Both
are very simple, well understood concepts. Their implementation in Go is also
more syntactically clear than in C.

~~~
rudolf0
I understand pointers and structs just fine, it's just that you would think a
modern language like Go would avoid use of pointers to structs and "bring-
your-own-buffer" type calling conventions except wherever possible. It makes
for ugly developer APIs, in my opinion.

That is, in a "friendly" language I expect to generate JSON like this (in
pseudocode):

    
    
        HashMap parsed = JSON::parse("{1: 2}");
    

not

    
    
        JSONObj obj;
        JSON::populate(&obj, "{1: 2}");

~~~
enneff
The former is how it might work in a dynamically typed language. In a
statically typed language, like Go, there are great benefits to decoding into
the fields of struct with fields of known types.

------
danso
I 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"

~~~
userbinator
I pronounce JSON as "jay-sawn" to avoid the confusion with the name. I've
heard "jiss-on" and various other mutations used as well.

~~~
izolate
American? The North American accent pronounces "Python" similarly, as "py-
THAWN" instead of "PIE-thn".

~~~
randallsquared
I usually pronounce it that way as well, I'm American, and it does rhyme with
Python that way for me.

------
w4rh4wk5
this looks quite familiar: [https://github.com/likexian/simplejson-
go](https://github.com/likexian/simplejson-go)

if anyone is interested i did some slight modifications to the project above
which are keep in my personal fork:
[https://github.com/W4RH4WK/simplejson](https://github.com/W4RH4WK/simplejson)

------
gorbachev
The name is a little "unfortunate", give that there's a JSON editor for Mac OS
X with the exact same name.

~~~
stonogo
Fortunately the go community has long experience with ignoring naming
conflicts.

