Skip to content

JSON Sort Keys

Recursively sort JSON object keys.

Input
Output

No result

About JSON Sort Keys

Sorting JSON keys arranges every object's keys alphabetically, and does so at every level rather than only at the top. The result is deterministic: two documents that differ only in the order their keys happen to be written produce byte-identical output once sorted.

That determinism is the point. Unsorted JSON is a poor fit for version control, because a tool that rewrites a file without changing its meaning still produces a diff in which every key appears to have moved. Sorting first reduces that noise to the changes that are actually real.

A detail worth knowing is that arrays are left alone. Array order is data — a list of steps, an ordered set of results — so reordering it would change the meaning of the document. Only object keys, whose order carries no semantic weight, are rearranged.

How to use JSON Sort Keys

  1. 1 Paste the JSON document.
  2. 2 Keys are sorted alphabetically at every level, and the result appears immediately.
  3. 3 Compare the output with a previous version to see only the changes that are genuinely new.

Frequently asked questions

Are array elements reordered as well?

No, and that is deliberate. Array order is meaningful — a sequence of steps, or a ranked list — so rearranging it would change what the document says. Only object keys are sorted, since their order carries no meaning in JSON.

How are keys that look like numbers handled?

They are compared as strings, as JSON keys always are. That means "10" sorts before "9", because the comparison is character by character rather than numeric. This occasionally surprises people working with numeric-looking identifiers.

Does sorting help with version control?

Considerably. A large part of the diff noise in JSON files comes from key order changing without any value changing. Sorting before committing makes reviews faster and makes a real functional change stand out instead of being buried.

Is the sort case-sensitive?

Keys are compared using standard string ordering, so uppercase letters sort before lowercase ones. Mixed-case conventions such as camelCase and snake_case can therefore interleave in a way that looks odd but is consistent and reproducible.

Free, online, and private

Free to use

JSON Sort Keys is completely free. There is no account to create, no login, and no hidden charge or usage limit.

Runs online in your browser

It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.

Your data stays private

All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.

How JSON Sort Keys behaves in detail

These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.

Parameter Value
Recursion applied at every level, including objects nested inside arrays
Comparison the default JavaScript string sort — UTF-16 code-unit order, not locale-aware
Arrays element order is never changed; only object keys are reordered
Output indent 2 spaces
Direction ascending only — there is no descending and no case-insensitive mode

Compiled from the implementation of this tool and checked against it by itoolnet.

What JSON Sort Keys does not do

Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.

  • The order is code-unit order rather than the order a reader expects: "Z" sorts before "a" because uppercase letters have lower code points, and "10" sorts before "2" because keys are compared as text and never as numbers.
  • Array order is deliberately untouched, which means an array of records keeps its original sequence while each record's keys are alphabetised, and there is no option to sort the array itself by one of its fields.
  • Duplicate keys cannot be reported or preserved: the document goes through the JSON parser first, so {"a":1,"a":2} is already reduced to {"a":2} before sorting starts, and no duplicate-key warning is issued.
  • The original key order is destroyed and there is no way to get it back — sorting is unconditional, with no "sort this branch only", no custom key sequence and no way to keep the file as it was written.

Tested and documented by itoolnet, the team that builds and maintains this site.

Share & embed this tool

Writing a guide or article? You are welcome to link to JSON Sort Keys with the snippet below. It is free, runs entirely in your browser, and needs no signup.