100% local — your data never leaves your browser

JSON Key Sorter — A Diff You Can Review

Sort JSON object keys alphabetically, at every level. Two files sorted the same way diff on what actually changed, not on key order.

Instant Private Zero cookies
Indentation

JSON input

JSON output

What this tool does

Every object’s keys, at every depth, in alphabetical order:

{ "server": { "port": 8080, "host": "localhost" }, "debug": true }
{
  "debug": true,
  "server": {
    "host": "localhost",
    "port": 8080
  }
}

Arrays keep their order

An object in JSON is an unordered set of name/value pairs — the specification says so, and no parser promises to preserve the order you wrote. An array is a sequence, and its order is a value.

["migrate", "seed", "start"]

Sorting that would turn a runbook into a wordlist. So arrays are left exactly as they are, at every level.

The order is by code point

Z comes before a, and a before é. That is Unicode code point order, not the alphabetical order of any particular language.

It is the only choice that gives the same output on every machine. A locale-aware sort puts ä next to a in German and after z in Swedish, so the same file would come back differently depending on who ran the tool — which defeats the main use of sorting, namely comparing two files that drifted apart.

Sorting is not canonicalising

A sorted document is easier to diff. It is not a canonical form you can hash and compare.

RFC 8785, the JSON Canonicalization Scheme, also pins down how numbers are written and how strings are escaped. This tool deliberately touches neither: 1.0 stays 1.0, and \u00e9 stays \u00e9. Two documents meaning exactly the same thing can therefore still sort to two different texts.

If you need a stable fingerprint of a JSON value, use a JCS implementation. If you need to see what changed between two configuration files, sort them both and diff.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Why are my arrays not sorted?
Because an array’s order is part of its meaning. `["read", "write"]` and `["write", "read"]` may be the same set to you and a different value to whatever reads the file — steps in a pipeline, priority order, a sequence of migrations. Object keys carry no order in the JSON data model; array elements do.
Why does Z come before a, and a before é?
The sort is by Unicode code point, not by the rules of any language. It is the only order that gives the same file on every machine: locale-aware collation would sort your keys differently in Stockholm and in Paris, and a sort meant for comparing files has to be reproducible above all.
Does sorting give me a canonical form I can hash?
Not quite, and the difference matters. Sorting the keys is one part of canonicalisation; RFC 8785 (JSON Canonicalization Scheme) also fixes number formatting and string escaping. This tool deliberately leaves both alone, so two documents that differ only in `1.0` versus `1` still sort to different text. Use a JCS implementation if you need a hash.

Related converters