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

Why is this not sorting? #40

Closed k-byun closed 3 years ago

k-byun commented 4 years ago
[
    {
        "destination": {
            "id": "xx-abc-b-diskuse01"
        }
    },
    {
        "destination": {
            "id": "xx-abc-b-diskalloc01"
        }
    }
]

=> diskalloc01 should appear first but it doesn't.

k-byun commented 4 years ago

Ruling out the string length to troubleshoot - this also does not sort: image [ { "destination": { "id": "xx-abc-b-diskuse01" } }, { "destination": { "id": "xx-abc-b-diskall01" } } ]

richie5um commented 4 years ago

Hi. The extension doesn’t rearrange array positions - instead it only rearranges keys as they has no impact on the meaning of the JSON.

k-byun commented 4 years ago

Good to know. I am using notepad++ to compare two JSON files but because the same content is positioned in different positions of within the same array in two different files, it's being detected as difference. Figured sorting both version would align and sort out this so I found your tool to pre-process this in vs code, then pass it to notepad++ - there might be a simpler process which I am not aware of.

I may make a pull request of your add-on extension to implement this later this week/month. Thank you

richie5um commented 4 years ago

Hi. Array sorting is not something this extension is designed for - if you want an array sorting extension then that should be a separate extension :). Array position order has meaning, dictionary key order doesn’t.

For your specific needs, if array position does not have meaning, then it may be easier for you to write a super simple JavaScript script to read in the file, sort the arrays in code, and write out the sorted arrays for comparison.

k-byun commented 4 years ago

Agreed. That's what I will do. Thanks!

FlorianWendelborn commented 3 years ago

@richie5um @k-byun I think this can be closed