← Back to tool

Sort · Normalise · Diff

Sort JSON Keys Alphabetically

Updated: June 2026

Sorting JSON keys alphabetically gives your data a canonical order. Because most systems emit keys in whatever order they were inserted, the same information can be serialised two different ways — and that wrecks diffs and caching. Sorting fixes it by putting every object in a single, predictable order.

Sort JSON Keys →

Free · No upload · Instant in the browser

Why key order is a problem

JSON objects are unordered by definition, but serializers still have to write the keys in some sequence. Different languages, libraries and versions choose differently, and even the same code can vary as fields are added over time. The values are identical, yet a line-by-line comparison lights up red because key 3 and key 7 swapped places. The signal you care about — what actually changed — is buried under noise.

Sorting removes the noise. Once every object's keys are alphabetical, two documents with the same data are byte-for-byte identical, and a diff shows only the values that genuinely differ.

Recursive, every level

A useful key sorter does not stop at the top level. It walks the entire tree, sorting the keys of every nested object while leaving array order untouched — arrays are ordered by design, so their elements must stay put. The tool here sorts recursively: an object three levels deep gets the same alphabetical treatment as the root. The result is a fully canonical form from top to bottom.

// before
{ "name": "x", "age": 9, "tags": ["b","a"] }

// after (keys sorted, array kept)
{ "age": 9, "name": "x", "tags": ["b","a"] }

Where sorted keys help

  • Version control — commit config and fixture files in a stable order so diffs stay small and reviewable.
  • Caching and hashing — a canonical form produces a stable hash, so equal data yields equal cache keys.
  • Snapshot tests — stop snapshots from churning just because a serializer reordered keys.
  • Readability — finding a key by name is faster when objects are alphabetised.

Sort and format in one step

Sorting pairs naturally with formatting. Turn on Sort keys, pick your indent, and the tool both alphabetises and pretty-prints in a single pass — or combine sorting with Minify to get a canonical compact form for hashing. Either way the work happens entirely in your browser. Your JSON is parsed, sorted and re-serialised locally, so configs and data containing private fields never get uploaded, and the sorted result is ready the instant you paste.

Frequently asked questions

How do I sort JSON keys alphabetically?

Paste your JSON and tick Sort keys A→Z. Every object is alphabetised at all nesting levels while array order is preserved.

Does sorting affect arrays?

No. Arrays are ordered by design, so their elements stay in place. Only object keys are reordered.

Why would I sort keys?

Sorted keys give a canonical form, which makes diffs smaller, hashes stable and snapshot tests reliable.

Can I sort and minify together?

Yes. Combine Sort keys with the Minify tab to produce a canonical, compact form ideal for hashing or comparison.