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.

Newline for each item in JSON array

See original GitHub issue

Is there an option to place each item in a JSON array on a new line regardless of the line of the length? I have quite a lot of the following:

[
    ["thing1"],
    ["thing2"]
]

And would like keep them this way instead of the whole thing becoming one line. I also think in general placing each item in an array on a new line is preferable.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:111
  • Comments:61 (19 by maintainers)

github_iconTop GitHub Comments

63reactions
lydellcommented, Sep 2, 2017

An idea worth discussing: What if we took the “3-or-more” rule from chained method calls and applied it to arrays (both in JS and in JSON)? One or two items would always be single-line (if it fits), while three or more items would always be multiline (even if it fits in a single line).

let a = [];
let b = [1];
let c = [1, 2];
let d = [
  1,
  2,
  3,
];
42reactions
Robinfrcommented, Sep 8, 2017

@maraisr that’s also fine in my opinion. Except it should be:

[
    1, 2, 3,
    4, 5
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add new line after each object in a JSON array when printing ...
This solution of adding additional line breaks between each of the properties in a JSON object seems to resolve the merge conflicts. The...
Read more >
How to handle newlines in JSON ? - GeeksforGeeks
First, we need to declare a variable as “json1” and then we need to assign the JSON to it. · In JSON object...
Read more >
array-element-newline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Processing JSON with jq -- newline - Fullstack.io
If an index value is omitted, then all of the elements are returned by the array index filter: Additionally, the .[] filter can...
Read more >
JSON - JavaScript - MDN Web Docs
All properties and methods of JSON are static (just like the Math object). JavaScript and JSON differences. JSON is a syntax for serializing...
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