DevKit
Formatter

JSON Sort Keys

Sort JSON object keys alphabetically, recursively.

Last updated: August 2026

Recursively sorts object keys alphabetically. Array order is preserved.

Share:

Was this tool helpful?

Deterministic key ordering

JSON objects have no required key order, so the same data can serialize a dozen different ways. Sorting keys alphabetically, recursively through every nested object, forces a single canonical layout. The data does not change; only the order of keys within each object does.

Why canonical order helps

The main payoff is clean diffs. If two tools or two runs emit the same data with different key orders, a line-based diff lights up with false changes. Sort both first and the diff shows only real differences. The same trick stabilizes snapshot tests and makes config files in version control change only when the data actually changes.

Example

Before:

{ "name": "Ada", "id": 7, "meta": { "z": 1, "a": 2 } }

After recursive sort:

{
  "id": 7,
  "meta": { "a": 2, "z": 1 },
  "name": "Ada"
}

Notice the sort reaches into meta too, reordering its keys as well as the top level.

When not to sort

Arrays are never reordered, their order is data, not presentation. Also, a few formats lean on object key order to mean something, and some tools emit keys in a deliberate sequence for readability. Sorting those loses intent. If order carries meaning in your system, leave it alone.

FAQ

How are numbers in keys sorted? As strings, not numerically, so "10" sorts before "2". That surprises people expecting numeric order.

Does sorting change values? No, only key order. For comparing two documents regardless of order, the JSON Diff tool ignores order outright.

Is the sort case-sensitive? Usually yes, so uppercase keys sort before lowercase ones under standard character ordering.