I am writing an endpoint to return data for Geckoboard, it excepts a format like so:
{
"item": [
{
"value": "274057"
},
[
"38594",
"39957",
"35316",
"35913",
"36668",
"45660",
"41949"
]
]
}
"item"
is an array of varying structures. How would I represent this data in Go?
Note: this is not on how I would unmarshal this, I need to generate this format.
This stuff is easier than you might think. It's just not that well documented for the casual reader. I would recommend
ffjson
over normaljson
tho. It's made up in such a manner that you don't need to change your syntax other than the library name.It's easy as this:
The downside of structs (even in
ffjson
still) is thatreflection
will always be used, which, in times that you're in need of high performance, you will waste a lot of CPU cycles.ffjson
is 2-3 times faster than normaljson
when you keep it to maps. This way the library can compile every data-structure you marshal and re-use it instead of constantly inspecting the data-integrity/structure withreflect
.