JSON Sort Keys
JSON Input
Loading editor…
Sorted Output
Loading editor…

JSON Sort Keys

Sort all keys in a JSON object alphabetically — ascending or descending — recursively through every nested level. Arrays are left in their original order.

A → Z or Z → A
Toggle between ascending and descending sort.
Recursive
Sorts keys at every nesting level, not just the root.
Arrays intact
Array element order is preserved — only object keys are sorted.
Client-side
No data is uploaded. Everything runs in your browser.

What Sorting Keys Is Actually For

Sorted keys have no effect on JSON semantics — a JSON object with keys in any order is equivalent to one with them sorted. The value is entirely in readability and comparison.

When reviewing API responses that vary between calls, sorted keys make it much easier to spot differences by eye. Two objects with the same keys but different insertion order look completely different when diffed as raw text. Sorting both sides first collapses that noise.

Config files that grow over time tend to accumulate keys in the order they were added. Alphabetising them makes it easier to find a specific key at a glance and to notice duplicates that sneak in during merges.

Sorting is also a useful pre-step before diffing. Paste both versions into Sort Keys first, then paste the sorted outputs into JSON Diff — the diff will only show genuine value changes, not key-ordering differences.

How Recursive Sorting Works

Every object in the JSON tree is sorted, not just the root. Nested objects inside arrays are sorted too.

Given this input:

{
  "user": {
    "zip": "12345",
    "name": "Alice",
    "age": 30
  },
  "active": true,
  "id": 1
}

The sorted output is:

{
  "active": true,
  "id": 1,
  "user": {
    "age": 30,
    "name": "Alice",
    "zip": "12345"
  }
}

Root keys sorted, nested object keys sorted. Arrays such as "tags": ["b", "a", "c"] are left in their original order — sorting array elements would change the data, not just the presentation.

Frequently Asked Questions

Does sorting keys change the meaning of the JSON?

No. JSON objects are unordered by definition — two objects with the same keys and values are identical regardless of key order. Sorting only affects how the text is presented, not what the data means.

Are arrays sorted?

No. Array element order is significant in JSON — sorting array elements would change the data. Only object keys are sorted. Objects nested inside arrays are sorted.

Is sorting applied recursively?

Yes. Every object at every nesting level is sorted, including objects inside arrays and objects nested inside other objects.

What is the sort order for uppercase vs lowercase keys?

Sorting uses locale-aware comparison (localeCompare). In practice, uppercase letters sort before lowercase — "Age" comes before "age" in A→Z order.

Is my data uploaded anywhere?

No. Sorting runs entirely in your browser. Nothing is transmitted.

More Tools