richie5um / vscode-sort-json

VSCode Extension to Sort JSON objects
https://marketplace.visualstudio.com/items?itemName=richie5um2.vscode-sort-json
MIT License
110 stars 19 forks source link

Try to sort selected key/value pairs within object by wrapping in braces #74

Open ian-h-chamberlain opened 1 year ago

ian-h-chamberlain commented 1 year ago

It seems there are some use cases that make it useful to select and sort a subset of a JSON object, instead of the needing a whole object. I myself have wished for a feature like this and it seems some people have also requested it (#57 and maybe some others).

As a proof-of-concept, I thought maybe we could just try surrounding the selection in {} and sort that, and if it works then strip off the {} and return the result!

The result is this PR, which I'll leave as a draft just to see if there's interest in taking a change like this. I haven't tested all kinds of corner cases yet, so it's possible this breaks something, but I think the basic concept is there! I was able to format the example in the above issue as well as some entries in my VSCode settings.json (one of the main use cases I had for this feature).