JSON Sort
Free JSON key sorter: order object keys A to Z or Z to A, recursively or at the top level, with natural order. Arrays keep their order. Runs in your browser.
How to use JSON Sort
- 1Paste or open your JSON.
- 2Choose A to Z or Z to A, and decide whether nested objects are sorted as well. Mode also covers Format, Minify, Tree and Escape.
- 3Copy the sorted JSON or download sorted.json.
What makes it better
- Ascending or descending key order
- Recursive sorting of nested objects, or top level only
- Natural order so item2 sorts before item10
- Arrays keep their item order, values stay untouched
- Sort Format or Minify output too, and open Tree mode, without retyping the input
About JSON Sort
JSON Sort rearranges the keys of every object in alphabetical order so two files can be compared or reviewed more easily. You choose ascending or descending order, whether to sort nested objects too, and whether numbers inside keys sort as numbers, so item2 comes before item10. Arrays keep the order of their items, and values and big numbers are copied exactly.
Common uses
- Normalise two JSON files before comparing them in a text diff or a code review.
- Keep a configuration or translation file in a stable, predictable key order.
- Make generated JSON deterministic so version control shows only real changes.
- Scan a long object for a key more quickly when the keys are in alphabetical order.
Example
Input
{"zebra":1,"config":{"timeout":30,"debug":false,"cache":{"ttl":60,"enabled":true}},"alpha":[{"y":1,"x":2}],"name":"demo"}Result
{
"alpha": [
{
"x": 2,
"y": 1
}
],
"config": {
"cache": {
"enabled": true,
"ttl": 60
},
"debug": false,
"timeout": 30
},
"name": "demo",
"zebra": 1
}Good to know
- Keys are compared by character code by default, so uppercase letters come before lowercase ones. Natural order compares digits as numbers and is a good choice for keys like item1, item2, item10.
- Only object keys are sorted. The order of items in arrays is meaningful and is never changed.
- Sorting changes the order of a file, which matters if a consumer depends on key order, a signature or a hash.
JSON Sort FAQ
How do I sort JSON keys alphabetically?
Paste your JSON and leave the order on A to Z. Every object, at every depth, is rewritten with its keys in alphabetical order. Switch to Z to A for the reverse.
Does sorting change the order of array items?
No. Array order usually carries meaning, such as a ranking or a sequence of steps, so items stay where they are. Only the keys inside objects, including objects that sit inside arrays, are reordered.
What is natural order?
It compares the digits inside keys as numbers, so item2 comes before item10, where plain alphabetical order would put item10 first. It is handy for keys that end in a counter.
Why do capital letters sort before lowercase ones?
Plain sorting compares character codes, and in Unicode all uppercase letters come before lowercase ones. So Zebra is placed before apple. Natural order uses a locale-aware comparison that places them together.
Can I sort only the top-level keys?
Yes. Untick Nested objects too and only the keys of the outermost object are sorted. Nested objects keep their original key order.