fvclaus / vsc-sort-json-array

Visual Studio Code extension that sorts arrays
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Feature-Request: Sort .jsonl files #8

Closed Whadup closed 4 years ago

Whadup commented 4 years ago

Would be great if this supported .jsonl files, where each line is a valid json object.

As a workaround, I put a comma at the end of each line and surround the whole file with [,] but that's rather annoying.

fvclaus commented 4 years ago

Yes, that sound reasonable. The current code also ruins the formatting. How did you get around that? I did not find any extension that support jsonl files.

I wrote some code that does what you describe automatically:

I have some unit tests and also tested it on one file:

jsonl_support

Currently I check for the file extension jsonl. Is this enough? Anything else I need to be aware of? The code can handle empty lines. Not sure if that would be even valid jsonl, but it certainly doesn't hurt to keep it.

Whadup commented 4 years ago

sounds perfect. Speaking of "valid", I'm not actually sure if .jsonl is a standardised format, or just something people came up with who need to write json arrays incrementally.

Whadup commented 4 years ago

As for the formatting part, you might even keep the old formatting if you don't sort the array, but only its indices. Then you can use the sorted indices to construct the output from the original line strings, no JSON-serialization required.

Unfortunately it's not as easy when sorting real json files, as in your other github issue...

fvclaus commented 4 years ago

I have build a pre-release for the 2.0.0 version that contains jsonl support here. You can install it, if you go to extensions in vscode, click on the ... on the top right and select Install from VSIX. I would like to hear you feedback, before I officially release the new version.

fvclaus commented 4 years ago

This is now part of 2.0.0