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

Array of objects in JSON #1402

Open
rinu opened this issue May 31, 2018 · 7 comments
Open

Array of objects in JSON #1402

rinu opened this issue May 31, 2018 · 7 comments

Comments

@rinu
Copy link

rinu commented May 31, 2018

Description

I need the beautified version not to start an array and object on the same line. This is for code folding with codemirror which only has one folding button per line. It defaults to folding the object but my intent was to fold the entire array. An annoying workaround is to enter a new line manually before folding.
The current version looks prettier so I would like it to be an option rather than the default.

Input

The code looked like this before beautification:

{"stuff":[{"thing":"other thing"},{"thing":"other thing"}]}

Expected Output

The code should have looked like this after beautification:

{
  "stuff": [
    {
      "thing": "other thing"
    }, {
      "thing": "other thing"
    }
  ]
}

Actual Output

The code actually looked like this after beautification:

{
  "stuff": [{
    "thing": "other thing"
  }, {
    "thing": "other thing"
  }]
}

Steps to Reproduce

I used indent_size: 2 as the only option. Can be reproduced on http://jsbeautifier.org/
I'm using js-beautify 1.7.5 from npm.

@bitwiseman
Copy link
Member

If you set brace-style to expand, you get closer to what you're looking for, but still not quite it:

{
  "stuff": [
  {
    "thing": "other thing"
  },
  {
    "thing": "other thing"
  }]
}

But actually, this is a bug, because expand should produce the expected output.

@rinu
Copy link
Author

rinu commented Jun 1, 2018

Even if the bug gets fixed, expand is still not perfect for this use case. Because braces always start on a new line, even if there is no array around. This I assume is not a bug but expected for expand

{"key1":{"i": "o"}}

Becomes

{
  "key1":
  {
    "i": "o"
  }
}

Rather than

{
  "key1": {
    "i": "o"
  }
}

@bitwiseman
Copy link
Member

@rinu Yes, you're correct. What you're describing is an enhancement.

@Huachao
Copy link

Huachao commented Dec 10, 2018

@bitwiseman any updates on this issue?

@bitwiseman
Copy link
Member

@Huachao
The linked bug provides interesting context for this issue. Thanks!
This enhancement is not high priority for the project. If you are interested in it, your help would be appreciated.

@bitwiseman bitwiseman modified the milestones: v1.9.x, v1.10.x Apr 29, 2019
@bitwiseman bitwiseman modified the milestones: v1.10.x, v1.10.xx Jan 14, 2020
@bitwiseman bitwiseman modified the milestones: v1.10.x, v1.11.x Apr 5, 2020
@bitwiseman bitwiseman modified the milestones: v1.11.x, v1.12.x Aug 13, 2020
@bitwiseman bitwiseman modified the milestones: v1.12.x, 1.13.x Aug 20, 2020
@stevekanter
Copy link

Does anyone expect this issue to ever get fixed? It's the ONE issue I have with js-beautify, unfortunately.

@bitwiseman
Copy link
Member

@stevekanter-arcticleaf
Nothing has changed. This project currently has very few contributors, so issues remain unfixed.
If you'd like to take a swing at fixing this issue, come to the gitter channel and lets talk about what you'd need to do to make this happen.

@bitwiseman bitwiseman modified the milestones: v1.13.1, v1.13.x Jan 8, 2021
@bitwiseman bitwiseman modified the milestones: v1.13.6, v1.13.x Jan 26, 2021
@bitwiseman bitwiseman removed this from the v1.13.7 milestone Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants