JSON Key Sorter

JSON Tools

How to use the JSON Key Sorter

Sort JSON keys recursively in one click:

1

Paste your JSON

Paste any JSON object or array — sorted or unsorted. The tool handles arbitrary nesting depth.

2

Choose sort direction

Select A→Z (ascending, default) or Z→A (descending).

3

Click Sort

All object keys at every nesting level are sorted recursively. Array element order is preserved.

4

Copy or download

Copy the sorted JSON to clipboard or download as a .json file.


When to use this tool

Use this to normalize JSON key ordering for cleaner diffs, comparisons, and readability:

  • Sorting keys before committing JSON config files to git to produce minimal, noise-free diffs
  • Normalizing two JSON objects before diffing them so key-order differences don't appear as false changes
  • Enforcing consistent key ordering in JSON config or schema files across a development team or codebase
  • Making a large unfamiliar JSON API response easier to read by sorting all keys alphabetically
  • Sorting JSON before running a byte-level comparison between two config files for equality checking
  • Alphabetizing keys in a hand-edited JSON file to make it easier to find fields quickly

Frequently asked questions

Q:Why would I sort JSON keys?
The JSON specification says object key order is undefined — parsers can return keys in any order. In practice, key order varies between environments and JSON generators. When JSON files are compared in git diffs, reordered keys appear as changed lines even though the data is identical. Sorting keys before committing avoids these false-positive diff lines and makes JSON config files easier to read consistently.
Q:Does sorting change the data?
No — only key order changes. JSON objects are unordered by specification, so sorted and unsorted JSON are semantically identical. All values, data types, and nesting are completely preserved. Sorted JSON is always equivalent to the original when parsed.
Q:Are nested objects sorted too?
Yes — sorting is fully recursive. All object keys at every nesting depth are sorted, not just the top-level keys. So { z: { b: 1, a: 2 }, a: 3 } becomes { a: 3, z: { a: 2, b: 1 } } — sorted at both levels.
Q:Are array element positions changed by sorting?
No — only object keys are sorted. Array element order is always preserved because arrays are ordered sequences and their position carries meaning. Sorting array elements would change the data semantics. If you need to sort array elements, use the jq Playground with sort_by(.field).
Q:Can I sort in both ascending and descending order?
Yes — choose A→Z for alphabetical ascending (the most common choice for git diffs and readability) or Z→A for reverse alphabetical descending if your use case requires it.
Q:Is this useful for JSON Schema or OpenAPI files?
Yes — sorting keys in a JSON Schema or OpenAPI file makes the spec easier to navigate (find a property alphabetically) and produces cleaner PR diffs when properties are added or changed. Many teams use sorted key order as a style convention for schema files.