Toolstia / JSON key sorter
JSON key sorter
Paste JSON and get the same data with every object key in alphabetical order. It is handy for comparing two files, keeping config files tidy and getting stable diffs in version control.
Arrays keep their order, because the order of items in a list is meaningful. Only the keys of objects are sorted.
How it works
- Paste your JSON.
- Choose A to Z or Z to A, and whether nested objects are sorted too.
- Copy the sorted JSON.
What gets sorted
The keys of every object, at every level if you leave nested sorting on. The order of items inside arrays is never changed, because the order of a list carries meaning.
Case and numbers
Keys are compared by character code by default, so capital letters come before lowercase ones. Tick ignore case to mix them. Keys that look like numbers are treated as text.
Indentation
Choose two spaces, four spaces, tabs or minified output. The values are not altered in any way.
Why sort keys
Two JSON files with the same data but a different key order look different in a diff. Sorting both first makes real changes easy to see.
Questions
Does it change my data?
No. Only the order of keys changes. Everything happens in your browser, and nothing you enter is sent anywhere.
Can it sort by value?
No. It sorts keys only.
What if my JSON has comments?
Standard JSON does not allow comments, so remove them first or the tool will report an error.