Using jq --stream -c
on the command line, I can format pretty JSON like this:
{
"object": {
"something": {
"key1": 123,
"key2": 456
},
"something_else": {
"key1": [
"value1",
"value2"
]
}
}
}
into this:
[["object","something","key1"],123]
[["object","something","key2"],456]
[["object","something","key2"]]
[["object","something_else","key1",0],"value1"]
[["object","something_else","key1",1],"value2"]
[["object","something_else","key1",1]]
[["object","something_else","key1"]]
[["object","something_else"]]
[["object"]]
I've looked through the Golang documentation for JSON but couldn't find anything similar. Is there such a function that I've missed?
More precisely I'd like to print the above JSON like so:
object.something.key1=123
object.something.key2=345
object.something_else.key1.0=value1
object.something_else.key1.1=value2
I've looked through the Golang documentation for JSON but couldn't find anything similar. Is there such a function that I've missed?
No, you haven't missed anything. The current JSON library doesn't support what you described "out of the box".
If you want this to work, you'll need to find a package that offers the flexibility you need or satisfy json.Marshaler
with a custom type yourself.