JSON Sort Keys

Sort every object key recursively for stable, deterministic JSON.

  • Runs locally in your browser
  • No upload required

Try it

Paste JSON. Every object key is sorted in your browser and never uploaded.

Sorted JSON
{ "a": 2, "b": 1 }
{
  "a": 2,
  "b": 1
}

Supported formats

Input
text
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Sorted every object key in 25 characters of JSON.

How it works

  • Scanned the JSON into a syntax tree without converting number literals.
  • Sorted each object's members by key using code-unit ascending order.
  • Re-emitted the tree with the chosen indentation; array order was preserved.
  • Sorting is locale-independent, so the result is stable across machines.

Methodology

  1. Tokenize the document with the F054 verbatim JSON scanner.
  2. Recursively sort each object's members by key; copy arrays unchanged.
  3. Re-emit the tree with the chosen indentation.

Usage

  1. Paste or type a JSON document.
  2. Choose 2 spaces, 4 spaces or a tab.
  3. Run the tool and copy the key-sorted JSON.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Nested objects

jsonSelect to copy
{
  "text": "{\"b\":1,\"a\":{\"d\":4,\"c\":3}}",
  "indent": "2"
}

Array order preserved

jsonSelect to copy
{
  "text": "{\"z\":[3,1,2],\"a\":true}",
  "indent": "2"
}

Big integer preserved

jsonSelect to copy
{
  "text": "{\"id\":123456789012345678901234567890,\"a\":1}",
  "indent": "2"
}

Limitations

Why sort keys

Two semantically equal documents can differ only in key order. Sorting keys makes diffs, hashes and reviewing stable and reproducible.

Frequently asked questions

Is the sort locale-aware?
No. Code-unit ascending order is used so the result is identical on every machine and in diffs.
Does it sort array values?
No. Only object keys are sorted; array order is data and is preserved.
Is my data uploaded?
No. The sort runs entirely in your browser and is never sent anywhere.

Sources

  1. RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format — IETF
  2. RFC 8785 — JSON Canonicalization Scheme (JCS) — IETF