Open movingobjects opened 7 months ago
I'd love to have (an option for?) empty arrays/objects be outputted on the same line.
For example, given the data:
const data = { a: [], b: {} };
Running stringify(data, { space: 2 }) returns:
stringify(data, { space: 2 })
{ "a": [ ], "b": { } }
Whereas JSON.stringify(data, null, 2) returns:
JSON.stringify(data, null, 2)
{ "a": [], "b": {} }
I find the latter, with the empty arrays/objects on the same line, much easier to read.
It also seems to matches how most other JSON tools handle empty arrays/objects (e.g., VSCode's Format Document command, https://jsonformatter.org/, https://www.jsonformatter.io/, and others).
Thanks!
That seems reasonable, and I agree it's easier to read. A new boolean option, say, collapseEmpty, should cover it.
collapseEmpty
I'd love to have (an option for?) empty arrays/objects be outputted on the same line.
For example, given the data:
Running
stringify(data, { space: 2 })
returns:Whereas
JSON.stringify(data, null, 2)
returns:I find the latter, with the empty arrays/objects on the same line, much easier to read.
It also seems to matches how most other JSON tools handle empty arrays/objects (e.g., VSCode's Format Document command, https://jsonformatter.org/, https://www.jsonformatter.io/, and others).
Thanks!