We have designed an "export" API which enables users to download a json file with information. The json is an array. Now we meet a little dilemma.
Call json.Marshal
directly (no indent, not so user-friendly)
[{"foo":"bar"},{"foo1":"bar1"}]
Call json.MarshalIndent
, or json.Indent(dst, src, "", " ")
(too much indent)
[
{
"foo": "bar"
},
{
"foo1": "bar1"
}
]
I want this kind
[
{"foo": "bar"},
{"foo1": "bar1"}
]
Any ideas?
If the structure is fixed, you can manually encode it like: