JSON Key Sorter
Sort the keys of a JSON document alphabetically at every level, A to Z or Z to A, while keeping array order as it is.
Was this tool helpful?
Thanks for the feedback!
This tool sorts the keys of a JSON document alphabetically at every level of nesting, A to Z or Z to A, and leaves the order of array items as it is. Sorted keys make two versions of a file easier to compare by eye, give cleaner diffs in version control and make large configs easier to scan. It works in your browser, so the JSON is not sent anywhere.
The options
| Option | Choices |
|---|---|
| Order | A to Z, or Z to A |
| Output format | 2 spaces, 4 spaces, Tabs, or Minified (one line) |
| Capital letters | Ignore case (a, B, c), or Uppercase first (B, a, c) |
How the sorting works
The tool parses your JSON and visits every value. For an object, it sorts the keys and then sorts whatever is inside each key. For an array, it keeps the items in their original positions but still sorts the keys of any objects inside it. Plain values such as text, numbers and booleans are not touched.
With Ignore case, keys are compared in lower case, so address, Age and name come out in that order. If two keys differ only in case, the exact spelling breaks the tie. With Uppercase first, the comparison uses plain character order, where every capital letter A to Z comes before every small letter, so Age comes before address. The Keys sorted counter adds up keys at all levels.
Worked example
Input:
{"name":"Asha","Age":29,"address":{"pin":"411001","city":"Pune"},"skills":[{"level":3,"lang":"SQL"}]}
A to Z, Ignore case, 2 spaces (Keys sorted: 8):
{
"address": {
"city": "Pune",
"pin": "411001"
},
"Age": 29,
"name": "Asha",
"skills": [
{
"lang": "SQL",
"level": 3
}
]
}
The same input with Uppercase first and Minified gives:
{"Age":29,"address":{"city":"Pune","pin":"411001"},"name":"Asha","skills":[{"lang":"SQL","level":3}]}
The skills array keeps its single object in place, but the keys inside that object are sorted.
Edge cases the tool cannot change
- Number-like keys always come first. JavaScript keeps keys that look like whole numbers, such as
"9"and"10", at the start of an object in ascending numeric order. So{"10":1,"9":2,"b":3,"a":4}sorted Z to A comes out as{"9":2,"10":1,"b":3,"a":4}. The letter keys are sorted, but the numeric ones stay at the front. - Duplicate keys collapse to one. If a key appears twice in the same object, the browser's JSON parser keeps the last value.
{"a":1,"a":2}becomes{"a":2}. - Very large integers lose precision. Numbers are stored as 64-bit floating point, so
12345678901234567890comes out as12345678901234567000. Keep long IDs as strings. - Invalid input is rejected. A missing brace gives a message starting "The JSON is not valid:" with the position the parser stopped at.
When to use it
Different tools write keys in different orders. One editor saves a settings file with keys in the order you added them, a script rewrites it in another order, and a version control diff then shows the whole file as changed when only one value moved. If everyone sorts keys the same way before saving, the diff shows just the line that really changed. The same habit helps code review, because a reviewer can find a key by scanning alphabetically instead of searching.
Sort keys before committing a config or translation file so that later changes show up as small, clear diffs. Sort two API responses the same way before reading them side by side, or let the JSON diff checker list the differences for you, since it ignores key order anyway. If you only need to shrink a file, the JSON minifier does that without reordering anything.
Frequently asked questions
How do I sort JSON keys alphabetically?
Does sorting JSON keys change the data?
Are arrays sorted too?
Why do numeric keys stay at the top after sorting?
What is the difference between Ignore case and Uppercase first?
Can I sort keys and minify JSON at the same time?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...