JSON Sort Keys

Paste JSON and every object comes back with its keys in alphabetical order, at every level of nesting. Arrays keep their order, and every value stays exactly as written.

How it works

The JSON is read by a parser that keeps numbers as the digits you wrote. Then every object, however deeply nested, has its keys sorted. The values move with their keys.

Arrays are never reordered, because in JSON the order of an array is part of the data. The objects inside an array are sorted, each on its own.

Like jq -S compares keys by character code, so uppercase letters come before lowercase and "10" before "2". Natural compares ignore case and read digits as numbers, so "item2" comes before "item10". If a key is written twice, both copies are kept in their original order.

How to use it

  1. 1 Pick A to Z or Z to A.
  2. 2 Pick Like jq -S for the order other tools produce, or Natural for the order a person expects.
  3. 3 Pick Indented or One line, and paste your JSON into the first box.
  4. 4 Copy the sorted JSON, or download it as a .json file.

Good to know

  • To compare two JSON files, sort both with the same settings, then compare them in the Diff Checker or JSON Diff. Moved keys no longer show up as changes.
  • Use Like jq -S when the result has to match another tool, such as jq -S, Python's json.dumps with sort_keys=True, or canonical JSON for signing.
  • Use Natural for files people read, such as translation files with keys like step2 and step10.
  • A key that appears twice stays twice. The JSON Validator lists those if you want to remove them.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Sorting JSON keys so two files can be compared

The keys of a JSON object have no meaning in their order. {"id": 7, "name": "Ada"} and {"name": "Ada", "id": 7} are the same object to every JSON reader. But they are different text, and text is what diff tools, code review and version control compare. Two services that write the same data in different key orders produce files that look completely changed. Sorting the keys of both files first removes that noise, so a diff shows only the values that really differ.

This tool sorts at every level. The top-level object is sorted, then each object inside it, then each object inside those, down to the deepest level. Arrays are walked into, so an array of user records has the keys of every record sorted, but the array itself is not reordered. That is deliberate. In JSON, the order of an array is part of its value: a list of steps, a ranking or a timeline means something different when it is shuffled.

There are two ways to compare keys. Like jq -S compares them by character code, one UTF-16 unit at a time. That is the order jq -S, Python's json.dumps(sort_keys=True) and the JSON Canonicalization Scheme (RFC 8785) produce, so use it when the result must match another program byte for byte, or when you are building canonical JSON to hash or sign. Its rules surprise people: all uppercase letters come before all lowercase letters, and "10" comes before "2" because "1" is a smaller character than "2". Natural ordering fixes both. It ignores case and reads runs of digits as numbers, so "step2" comes before "step10", which is what a person reading a translation file expects.

Sorting through JSON.parse would damage the data in two ways, which is why this tool uses its own parser. JSON.parse rounds numbers longer than about 16 digits, so a 64-bit ID changes. It also keeps only the last copy of a key written twice. Here every number keeps its digits, and a duplicate key keeps both copies, in the order they were written, because the sort is stable.

The output is indented with two spaces by default, or written on one line if you want a compact canonical form. Either way the values are untouched: only the order of keys inside objects changes. Everything runs on this page, so configuration files and API responses with private data are never uploaded.

Frequently asked questions

Why are my arrays not sorted?

Because their order is data. ["first", "second"] and ["second", "first"] are different values in JSON, while {"a": 1, "b": 2} and {"b": 2, "a": 1} are the same object. Sorting an array would change what the file says.

Why does Z come before a?

Like jq -S compares keys by character code, where every uppercase letter comes before every lowercase one. That is what jq, Python and canonical JSON do, so the output matches theirs. Pick Natural to ignore case.

Will sorting change any values?

No. Numbers keep their exact digits, so a 20-digit ID is not rounded, and strings are unchanged. Only the order of keys inside objects changes.

Is my JSON uploaded?

No. It is parsed and sorted in this page.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.