Skip to content
Jellykit

JSON Key Sorter

Sort the keys of every object in a JSON document, at every depth, from A to Z, naturally or by code point.

  • Runs on your device
Loading tool

About JSON Key Sorter

Two JSON files that hold the same data can list their keys in a different order, which makes them hard to compare and noisy in version control. Paste a document here and the keys of every object, however deeply nested, come out in a predictable order, while arrays keep the order their items were in.

Numbers are copied exactly as written, so long identifiers and values like 1.10 are not rounded on the way through.

How it works

  1. The document is read by a strict JSON parser that keeps every number exactly as it was written.
  2. Each object’s keys are reordered. A to Z ignores case; Natural also compares runs of digits by their value, so item2 comes before item10; Code point follows character codes, the order RFC 8785 uses.
  3. Arrays are left in their order, because in JSON the position of an item is part of its meaning.

Questions

Why are arrays not sorted?

The order of an array is data: the first step of a list, the newest entry in a log. Sorting it would change what the document says, so only the keys of objects are reordered.

How are accented letters ordered?

By character code after ignoring case, so é sorts after z rather than next to e. This keeps the order the same in every browser and every language setting, which matters when the result goes into version control.

What happens to a key that appears twice in one object?

A JSON object can hold each key only once, so the last value is kept, as every JSON parser does. A warning gives the line and column of the first repeat so you can fix the source.

Is there a size limit?

Up to 5 MB of text, which sorts in well under a second on an ordinary laptop. Documents nested more than 1,000 levels deep are refused.

Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.