Skip to content

Keep empty arrays & objects on same line #15

@movingobjects

Description

@movingobjects

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions