JSON Key Sorter

Sort JSON object keys alphabetically and recursively — in your browser.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

JSON key sorter

The same JSON data can be written with its keys in any order, which makes two otherwise-identical files diff noisily and config files drift over time. This tool returns your JSON with every object’s keys sorted alphabetically and recursively, giving you a single canonical ordering that diffs cleanly.

How it works

The sorter parses your JSON, then rebuilds it: for each object it lists the keys, sorts them as strings (ascending A→Z or descending Z→A), and re-emits them in that order, descending recursively into every nested object. Arrays keep their order by default, since element position is usually significant; you can optionally sort string-only arrays as well. Finally the result is serialised with your chosen indentation — 2 spaces, 4 spaces, a tab, or minified.

Example

This input:

{ "name": "api", "auth": { "type": "key", "id": 7 } }

sorted ascending becomes:

{
  "auth": {
    "id": 7,
    "type": "key"
  },
  "name": "api"
}

auth now precedes name, and inside auth the keys are sorted too. Sorting keys into a stable order makes JSON deterministic and easy to diff. Everything runs in your browser — your JSON never leaves your device.

Ad placeholder (rectangle)