A JSON sorter for predictable key order
JSON objects are unordered by definition, yet the order in which keys are written matters a great deal to people. Two files with the same data in a different order produce a noisy diff, and a long config is hard to scan when keys appear at random. This JSON sorter rewrites every object with its keys in alphabetical order, at every nesting level, so the same data always produces the same text.
Example
Input:
{"version":"2.1.0","name":"svc","deps":{"zod":"^3","Express":"^4","axios":"^1"},"files":["item10","item2","Item1"],"sizes":[10,9,100]}
Sorted A → Z with Also sort arrays of values ticked:
{
"deps": {
"axios": "^1",
"Express": "^4",
"zod": "^3"
},
"files": [
"Item1",
"item2",
"item10"
],
"name": "svc",
"sizes": [
9,
10,
100
],
"version": "2.1.0"
}
With the checkbox cleared, the keys are sorted the same way but files and sizes keep their original order.
How the comparison works
- Case-insensitive.
Expresssorts betweenaxiosandzodrather than before all lowercase keys, which is how a person would alphabetize. Keys that differ only in case, such asBandb, are still placed in a consistent order. - Natural numbers. Digits inside names are compared as numbers, so
item2comes beforeitem10. A plain character sort would putitem10first. - Z → A reverses the result at every level.
What "Also sort arrays of values" does
Arrays are ordered lists, and in most data their order means something, so they are left alone by default. When the option is ticked, an array is sorted only if every element is a simple value: a string, number, boolean or null. Numbers are compared numerically, so [10, 9, 100] becomes [9, 10, 100]. Arrays that contain objects or other arrays are never reordered, although the keys inside those objects are still sorted.
Use the option for sets stored as arrays, such as tags, permissions or feature flags, where only membership matters.
One ordering rule you cannot override
Keys that look like whole numbers, such as "2" and "10", are always placed first in ascending numeric order, even with Z → A selected. JavaScript objects store integer-like keys that way, and the output is written from a JavaScript object. Other keys follow in the order you chose.
Why sort JSON?
- Smaller diffs. Sort both versions of a file before comparing them in the JSON diff tool, and only real changes remain.
- Consistent configs. Committing sorted translation files, feature-flag lists and settings keeps merge conflicts down when several people edit them.
- Faster review. A reviewer can check that an expected key exists without searching.
- Spotting near-duplicates. Keys like
userIdanduserIDend up next to each other.
Note that this is not the canonical form defined by RFC 8785 (JSON Canonicalization Scheme), which orders keys by raw UTF-16 code units and is used for hashing and signatures. Use this sorter for readability, not for producing signed payloads.
If you only need sorted keys as part of formatting, the Sort keys checkbox in the JSON formatter does the same for objects. Sorting runs entirely in your browser; your data is only sent to our server when you use Load URL or Save & Share.