JSON Key Sorter

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

Free online JSON key sorter. Recursively alphabetise object keys (A to Z or Z to A), optionally sort string arrays, and pick your indentation. Privacy-first: your JSON never leaves your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

Does it sort keys at every nesting level?

Yes. Keys are sorted recursively through every nested object. Array order is preserved by default so element positions are not disturbed.

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.

When sorted keys make a real difference

Version control. Many JSON-generating systems do not guarantee key order. When two developers independently modify the same config file and their tools output keys in different orders, git diff shows a long, noisy diff that hides the actual changes. Sorting keys before committing establishes a canonical order so diffs show only real changes.

Content-addressed hashing. If you need to hash a JSON document — for a cache key, an ETag, or a digital signature — you need deterministic serialisation. Two objects with the same keys and values but different key orders produce different hashes. Sorting keys first ensures that equivalent documents produce the same hash.

API response normalization. Some systems combine data from multiple upstream sources, each of which may return keys in a different order. Sorting before comparison or storage avoids treating semantically identical objects as different.

Readability. A large JSON config with dozens of top-level keys is easier to scan when alphabetised — you can jump straight to the section you want rather than scanning the entire file.

How string comparison works for keys

Keys are sorted as Unicode strings using JavaScript’s default comparison, which uses code point order. The practical implications:

  • Uppercase letters (AZ, code points 65–90) sort before lowercase letters (az, code points 97–122) in ascending order.
  • Digits (09) sort before both uppercase and lowercase letters.
  • Underscore _ (code point 95) sorts between uppercase and lowercase.

So an ascending sort of ["name", "Age", "ZIP"] produces ["Age", "ZIP", "name"]. If you want case-insensitive sorting, you would need to pre-process the keys — this tool applies standard Unicode code-point ordering.

Sorting string arrays — when to enable it

By default, only object keys are sorted, and array element order is preserved. Arrays representing lists where order is meaningful (records, steps, IDs) must not be reordered — enabling array sorting on those would corrupt the data.

The optional string-array sorting is appropriate only when your arrays are unordered sets of strings: tag lists, permission sets, feature flags. Enabling it for mixed-type arrays or arrays of objects is blocked deliberately, because those types almost always have meaningful ordering.