{ } JSON Workbench0 network requests. Check DevTools

"Sort JSON Keys":{ }

Paste JSON to sort every object's keys alphabetically, recursively through nested objects. Arrays keep their order since element position is semantic. Produces deterministic output for clean diffs and stable snapshot tests. 100% in-browser, nothing uploaded.

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

  1. Paste JSON into the Input pane.
  2. The tool recursively sorts object keys A→Z at every level.
  3. Array element order is preserved: elements are never reordered.
  4. Copy the sorted, deterministic output.
  5. Re-run on two files to make them diff-friendly.

Examples

Top-level + nested keys sorted

Input
{"name":"api","address":{"zip":"1","city":"NY"}}
Output
{"address":{"city":"NY","zip":"1"},"name":"api"}

Edge case: arrays are NOT reordered

Input
{"tags":["z","a","m"],"id":2}
Output
{"id":2,"tags":["z","a","m"]}

Edge case: numeric-looking keys sort as strings

Input
{"10":"a","2":"b","1":"c"}
Output
{"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.

Related tools