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

[FeatureRequest] format array items each on new line #80

Open
konopka opened this issue Nov 11, 2019 · 6 comments
Open

[FeatureRequest] format array items each on new line #80

konopka opened this issue Nov 11, 2019 · 6 comments
Assignees

Comments

@konopka
Copy link

konopka commented Nov 11, 2019

Add option to format array items on new lines.
Array:
["a", "b", "c"]
should be formatted like this:

[
  "a", 
  "b", 
  "c"
]
@sunjw sunjw self-assigned this Nov 12, 2019
@KurzedMetal
Copy link

KurzedMetal commented Nov 16, 2020

I was about to suggest exactly this, I'd love to see this feature implemented.

This is not only something that makes it visually pleasant to see, but also enables quicker diff comparisons between two json files if each item is in a new line after applying a Format and Sort.
Having all items in a single line makes it harder to read the diff, specially if there's lots of items in the list.

@aslze
Copy link

aslze commented Dec 8, 2020

Hi,

I usually favor the original compact format, especially for numbers.

I often store numerical data in JSON (3D vectors, index arrays, coordinates lists, ...) and things like this are more convenient (especially with large numerical arrays):

"position": [0, 0,  10.5],
"vertices": [-1.0, 0, 1.15, -3.212, 10, 0, -34.1]

What I'd suggest is to limit these arrays to a maximum configurable line length (or max number of items per line), so they don't grow indefinitely. For example, in my own C++ JSON formatter, I write up to 10 numerical elements per line, and then add a newline to cotinue for the next 10.

For arrays of strings, unless they are very short, I'd say I prefer one per line.

@Owyn
Copy link

Owyn commented Jul 9, 2022

Such option would indeed be nice

@sunjw
Copy link
Owner

sunjw commented Jul 10, 2022

I hope I can have time to figure this out, but it is really a difficult feature. Because when it comes an array, algorithm cannot know how long it will be, or is there some functions/classes in it (or is it a pure number/variable array). It can only know the result after result is produced. In my current algorithm, it only see 1 or 2 words ahead, and can only look back (already produced result), so "put a pure number array in one line" is not easy to implement with current algorithm.

I'll keep this issue open, but I don't think it will be resolved in short time.

@knw257
Copy link

knw257 commented Jul 10, 2022

@sunjw I think the request has been confused. The original request is simply to add an option within the plugin settings to split each item in a JSON array to a new line, rather than keeping them all on the same line. The suggestion of making the algorithm "smart" in identifying e.g. a pure number array was, I think, more of a "would be nice" element of the feature, but not a requirement. If the simpler option could be implemented first, it would be more than sufficient for my, and I think most users', needs.

@sunjw
Copy link
Owner

sunjw commented Jul 11, 2022

@knw257 I'll see what I can do.

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

6 participants