question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array of objects in JSON

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
stevekanter-arcticleafcommented, Sep 11, 2020

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

0reactions
bitwisemancommented, Sep 15, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Array Literals
Arrays in JSON are almost the same as arrays in JavaScript. In JSON, array values must be of type string, number, object, array,...
Read more >
JSON Array Structure
A JSON array contains zero, one, or more ordered elements, separated by a comma. The JSON array is surrounded by square brackets [...
Read more >
JSON Array
JSON array represents ordered list of values. JSON array can store multiple values. It can store string, number, boolean or object in JSON...
Read more >
Use a JSON array with objects with javascript
I have a function that will get a JSON array with objects. In the function I will be able to loop through the...
Read more >
JSON Array - Multi-dimensional Array in JSON
JSON array can store string , number , boolean , object or other array inside JSON array. In JSON array, values must be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found