100% local

JSON Key Sorter

data_object JSON Input
task_alt Output

JSON Key Sorter

Reorder every object key in a document so two files line up and version control diffs stop reporting noise. Nested objects are sorted at every level and array order is left alone.

A canonical key order is worth having because JSON has no inherent one. Two services can emit the same data with keys in different sequences, and a text diff will call that a change. Sorting both sides first removes the disagreement, so what remains in the diff is a real difference in values.

Sorting descends through objects and through the objects inside arrays, but never reorders array elements themselves. Array position usually carries meaning, so shuffling it would change the data rather than normalize it. The output is re-emitted with two space indentation, which also makes this a convenient way to normalize formatting and key order in one pass.

The sort is locale aware, not byte order

Keys are compared with the browser locale collation rather than by character code, and the two disagree more often than you would expect. Locale collation treats letters as primary and case as a tiebreaker, so alpha sorts before Beta. Byte order compares code points, where every uppercase ASCII letter comes before every lowercase one, so Beta would sort before alpha. Feed in Beta, alpha, and Alpha and this tool returns alpha, Alpha, Beta.

Accented and non Latin characters show the difference more sharply. The key école has a code point above z, so byte order would place it after zebra. Locale collation treats it as an e and places it first. If you are producing a canonical form that a program on another platform has to reproduce byte for byte, locale collation is the wrong tool, because the result depends on the collation tables of the environment that produced it.

Sorting is also not natural sort. The keys item2 and item10 are compared as text, so item10 lands before item2 because the character 1 precedes 2. There is no numeric awareness inside a key name. If you need numbered keys in numeric order, pad them with leading zeros at the source, or restructure the data as an array where position is explicit.

How key pairs actually order

Each row is a real pair of keys and the order this tool produces in ascending mode, next to what a plain code point comparison would have produced.

KeysThis toolNotes
"Beta", "alpha"alpha, BetaByte order would give Beta, alpha. Letters outrank case here.
"Alpha", "alpha"alpha, AlphaSame letter, so case decides and lowercase comes first.
"zebra", "école"école, zebraByte order would give zebra, école. The accent is folded to e.
"item2", "item10"item10, item2Not a natural sort. Compared as text, so 1 precedes 2.
"id", "_id"_id, idUnderscore sorts before letters in both schemes, so this one agrees.

Sorting a nested object

Keys are reordered at the top level and inside the nested object. The array keeps its original element order.

Input
{
  "name": "Ada",
  "tags": ["z", "a"],
  "meta": { "updated": 2, "created": 1 },
  "active": true
}
Output
{
  "active": true,
  "meta": {
    "created": 1,
    "updated": 2
  },
  "name": "Ada",
  "tags": [
    "z",
    "a"
  ]
}

The tags array still reads z, a because element order is data. Inside meta, the keys were reordered independently of the parent.

Common Pitfalls

Numeric keys ignore the sort direction entirely

Keys made only of digits are stored ahead of every string key in ascending numeric order, and re-serializing cannot override that. Sorting the object with keys b, 10, a, 2 in descending mode returns 2, 10, b, a. The digit keys came out ascending and first, in direct contradiction of the direction you selected. This is a property of the object model, not a bug in the comparison, and no browser based tool can avoid it.

descending: {"b":1,"10":2,"a":3,"2":4}
       ->  {"2":4,"10":2,"b":1,"a":3}

Sorted output is not a portable canonical form

Because collation is locale dependent and numeric keys are repositioned, two environments can produce different byte sequences from the same input. Do not hash sorted output and compare it against a hash computed by another implementation. Use a specified canonicalization scheme such as JCS, which mandates code point ordering, if you need that guarantee.

Sorting before diffing helps, but only for objects

Sorting removes key order noise from a diff, which is its most common use. It does nothing about array order noise, because arrays are deliberately left alone. If two documents contain the same list in a different sequence, a diff will still report every position as changed.

How to Use

  1. Paste your JSON: Drop in a config file or a payload whose keys arrive in an unpredictable order.
  2. Choose sort order: Select ascending (A→Z) or descending (Z→A) from the dropdown.
  3. Click Sort: All object keys are sorted recursively, including nested objects. Arrays remain in their original order.

Key Features

  • Recursive sorting: all nested object keys are sorted at every level
  • Ascending and descending sort options
  • Preserves array element order: only object keys are reordered
  • Formatted output with 2-space indentation

Use Cases

  • Standardizing JSON key order for consistent version control diffs
  • Organizing configuration files for better readability
  • Preparing JSON for comparison: sorting both files before diffing reduces noise

Frequently Asked Questions

Are nested keys sorted too?

Yes, at every level. Objects nested inside other objects and objects nested inside arrays are all sorted, independently of their parent.

Does sorting change array order?

No. Only object keys are sorted. Array element order is preserved.

Does sorting change my data?

No. Only the order of object keys is changed. All values, arrays, and nested structures remain identical.

Why sort JSON keys?

Sorted keys make JSON easier to read and compare. They also reduce diff noise in version control, since key order changes won't appear as modifications.

Is the sort alphabetical or by character code?

Keys are compared using browser locale collation, so letters take priority over case and accents fold to their base letter. Feeding in Beta, alpha, Alpha returns alpha, Alpha, Beta, which is different from a code point sort.

Why are my numeric keys not following the sort direction?

Keys consisting only of digits are held separately from string keys and always emitted in ascending numeric order, before every other key. Descending mode cannot change that. It is a property of how JavaScript objects store keys, so it affects every browser based JSON tool.

Can I sort array elements too?

No, and that is deliberate. Array position usually carries meaning, such as ranking or sequence, so reordering elements would change your data rather than normalize its shape. Only object keys are reordered.