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

feature request: sort portion of JSON #57

Closed alanlivio closed 2 years ago

alanlivio commented 3 years ago

It would be interest sort a portion of valid json. Today the sort, even if a selection, must be a valid json. For instance, I would like to sort only the fields C, B, A bellow.

{
  "C":  "value",
  "B":  "value",
  "A":  "value",
  "NotImportant":  "value",
}
richie5um commented 3 years ago

Good idea, but that feels impractical (aka, very difficult ;-)) - but let me know if you have any ideas.

When I have this, I just use the simple ‘sort lines’ extension.

alanlivio commented 3 years ago

Hi @richie5um. Thank you for your answer.

When I have this, I just use the simple ‘sort lines’ extension. I tried that. But my problem is when the is arrays objects. For instance, I would like to sort only the C, B, A bellow.

{
  "C":  "value",
  "B": {
     "BC":  "value",
     "BB":  "value",
     "BA":  "value",
   },
  "A": "value",
  "NotImportant":  "value",
}
alanlivio commented 2 years ago

I understand the difficulty of this and I close the issue.

ian-h-chamberlain commented 1 year ago

Hi, I had the idea to try just wrapping the selection in {} and sort that, and it seems to work! I opened a draft PR #74 to add this feature to the extension if you are interested.