JSON Sorter

Sort every object key in a JSON document alphabetically — recursively, through all levels of nesting — to produce stable output that's easy to diff, review and compare.

json-sorter · runs locally

What this JSON sorter does

Two JSON documents can contain identical data and still look completely different, because object keys can appear in any order. That’s harmless to parsers and miserable for humans: diffs light up with moved lines, code review noise buries real changes, and comparing two API responses by eye becomes guesswork. This sorter normalizes a document by ordering every object’s keys alphabetically — at every nesting level — while leaving array order, values and structure untouched.

Combined with consistent indentation (choose 2 spaces, 4 spaces or tabs), sorted JSON gives you a canonical form: the same data always serializes to the same text.

How to sort JSON keys

  1. Paste your JSON into the input box.
  2. Choose A→Z or Z→A and an indentation style.
  3. Click Sort keys and copy the normalized result.

Where sorted JSON pays off

Sort before committing configuration files so future diffs show only real edits; sort two API responses before comparing them; sort translation files so every locale lists keys in the same order and missing entries stand out. For an automated comparison after normalizing, feed both documents to the JSON Diff tool — sorted input makes its output cleaner too.

Frequently asked questions

Does sorting keys change what the JSON means?

For virtually all consumers, no — the JSON specification defines objects as unordered collections, so {"a":1,"b":2} and {"b":2,"a":1} are equivalent data. Only sort if you know nothing downstream (rare, non-compliant code) depends on key order.

Are arrays sorted too?

No. Array order is meaningful in JSON — [1,2,3] and [3,2,1] are different data — so the sorter recurses into arrays to sort the keys of objects inside them, but never reorders the array elements themselves.

Why sort JSON keys at all?

Stability. Sorted keys make two documents comparable line-by-line: version-control diffs shrink to real changes, code reviews get easier, and duplicate configuration is easier to spot. Many teams sort package.json-style files for exactly this reason.

How are the keys ordered?

Alphabetically using locale-aware comparison, ascending by default with a Z→A option. Sorting is applied recursively, so nested objects at any depth come out in the same predictable order.