Sort JSON keys alphabetically at every level

Paste JSON and every object key is put in alphabetical order, at every nesting level, so two files with the same data line up in a diff and config files stay predictable.

Live demo · real result from this tool
Order

Sorted JSON

{  "alpha": {    "beta": [      3,      1,      2    ],    "delta": true  },  "Mid": null,  "zeta": 1}

Processed on your device — nothing is uploaded.

How to use the JSON key sorter

  1. Paste your JSON into JSON.
  2. Pick the Order: A → Z or Z → A.
  3. Leave Ignore case ticked for dictionary order, or untick it for strict character order.
  4. Tick Also sort arrays of plain values if lists such as tags or allowed hosts should be sorted too.
  5. Choose an Indent (2 spaces, 4 spaces, tabs or none) and copy or download the Sorted JSON.

What it does and when to use it

Different programs write the same data with keys in a different order. A diff of two API responses, two exported settings files or two lock files then shows dozens of moved lines that are not real changes. Sort both documents with the same settings and the diff shows only what actually changed. It also helps when you keep JSON fixtures or translation files in Git and want new keys to land in a predictable place.

After sorting, compare the two versions with JSON diff, which also ignores key order on its own. To see every key path in a large document, use the JSON key extractor; for indentation alone, the JSON formatter has a simpler “Sort keys A–Z” option.

How it works

The JSON is parsed in your browser and rebuilt from the top down. At each object, the key list is sorted and the object is rebuilt in that order. With Ignore case, keys are compared with English locale rules at base strength, so case and accents are ignored and ties fall back to character code order. The result is printed with JSON.stringify at your chosen indent.

One JavaScript rule shows through: integer-like keys such as "2" and "10" are always placed first, in numeric order, because that is how JavaScript objects store them. The same happens in any JavaScript-based tool.

Worked examples

A small package.json, minified output:

{"version":"1.0.0","name":"app","scripts":{"test":"vitest","build":"vite build","Dev":"vite"},"keywords":["z","a"]}
{"keywords":["z","a"],"name":"app","scripts":{"build":"vite build","Dev":"vite","test":"vitest"},"version":"1.0.0"}

The nested scripts keys are sorted too, and keywords keeps its order. With Ignore case off, scripts becomes {"Dev":"vite","build":"vite build","test":"vitest"}.

With Also sort arrays of plain values ticked, {"tags":["b","A","c"],"nums":[10,9,100],"items":[{"z":1,"a":2}]} gives:

{"items":[{"a":2,"z":1}],"nums":[9,10,100],"tags":["A","b","c"]}

Limits and tips

  • Very large integers and long decimals pass through JSON.parse, so integers above 2^53 may change. Keep such IDs as strings.
  • Comments are not allowed. Clean them up with JSON repair first.

Frequently asked questions

Does sorting keys change what the JSON means?
No. RFC 8259 defines an object as an unordered collection of name/value pairs, so a parser must not depend on key order. Array order does matter, which is why arrays are left alone unless you tick "Also sort arrays of plain values".
Why does item10 come before item2?
Keys are compared character by character, so "item1" and "item10" sort before "item2". There is no natural (number-aware) sort. Zero-pad numbers in key names, such as item02, if you need numeric order.
What does "Ignore case" change?
With it ticked (the default), "Dev" sorts between "build" and "test", as a dictionary would. With it off, keys are sorted by character code, so every capitalised key comes before every lower-case one, which matches what many command-line tools do.
Are arrays of objects sorted too?
The objects inside arrays get their keys sorted, but the items keep their order. "Also sort arrays of plain values" only reorders arrays that hold nothing but strings, numbers, booleans or null; numbers are sorted by value.
Does it keep duplicate keys?
No. The document is parsed first, and like most parsers this keeps only the last value of a duplicated key. Run the JSON validator first if you suspect duplicates; it lists them with their line numbers.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close