Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep empty arrays & objects on same line #15

Open
movingobjects opened this issue Apr 11, 2024 · 1 comment
Open

Keep empty arrays & objects on same line #15

movingobjects opened this issue Apr 11, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@movingobjects
Copy link

movingobjects commented Apr 11, 2024

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:

{
  "a": [
  ],
  "b": {
  }
}

Whereas JSON.stringify(data, null, 2) returns:

{
  "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!

@ljharb ljharb added the enhancement New feature or request label Apr 12, 2024
@ljharb
Copy link
Owner

ljharb commented Apr 12, 2024

That seems reasonable, and I agree it's easier to read. A new boolean option, say, collapseEmpty, should cover it.

@ljharb ljharb added the help wanted Extra attention is needed label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants