What is sorting JSON keys and why do it?
Object key order in JSON is insignificant to parsers but noisy for humans and version control. Recursively alphabetizing keys yields a canonical form, so two equivalent documents produce identical text, shrinking diffs, killing merge conflicts, and stabilizing snapshot tests.
Arrays keep their order because element position is semantic. Everything runs in-browser; nothing is uploaded.
Edge cases & gotchas
- Arrays of objects: element order is preserved, but each object's keys are sorted.
- Numeric string keys sort lexicographically, not numerically (
"10"<"2"). - Uppercase precedes lowercase in ASCII order (
"Z"<"a"). - Unicode/emoji keys sort by code point.
- Duplicate keys (invalid JSON) collapse to one via repair parsing.
- Sorting is idempotent: running it twice yields identical output, which is ideal for CI checks.
How to use
- Paste JSON into the Input pane.
- The tool recursively sorts object keys A→Z at every level.
- Array element order is preserved: elements are never reordered.
- Copy the sorted, deterministic output.
- Re-run on two files to make them diff-friendly.
Examples
Top-level + nested keys sorted
{"name":"api","address":{"zip":"1","city":"NY"}}{"address":{"city":"NY","zip":"1"},"name":"api"}Edge case: arrays are NOT reordered
{"tags":["z","a","m"],"id":2}{"id":2,"tags":["z","a","m"]}Edge case: numeric-looking keys sort as strings
{"10":"a","2":"b","1":"c"}{"1":"c","10":"a","2":"b"}FAQ
Does sorting change my data?
No, only key order changes. Values and array order are untouched.
Are nested objects sorted?
Yes, recursively at every depth.
Does it sort arrays?
No. Array order is meaningful, so elements stay in place. For a tabular view instead, try JSON to Table.
How are numeric keys sorted?
As strings: "10" sorts before "2" because comparison is lexicographic, not numeric.
Why sort JSON keys?
Deterministic output for smaller git diffs, easier file comparison with Compare JSON, and reliable snapshot tests.
Is it case-sensitive?
Yes. Sorting is lexicographic (ASCII), so uppercase sorts before lowercase.