You mean like this? http://play.golang.org/p/mMh7HGuTbe
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...
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.
I don't understand this. Can you clarify why you think this is a good idea?
My experience with languages that have implicit "references" (Python, Java, JavaScript) is that it's not clear when you're sharing and when you're copying data, leading to bugs and unnecessary allocations, respectively.
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}");