JSON Key Sorter (Stable Key Order for Cleaner Diffs)

Automatically standardize JSON key order to make reviews and comparisons easier.

Choose all levels or top level only. Array order stays intact.

Cleaner diffs with fixed key order
Array order is preserved
Indentation formatting in the same run
Processing runs entirely in this page (nothing is uploaded).

Tool

Sort and format JSON in one step, then copy or download the result.

Shortcut: Ctrl / Cmd + Enter to run

Sample (Before / After)

Input

{"b":1,"a":{"d":4,"c":3},"arr":[{"y":2,"x":1},3]}

All-level sort (2 spaces)

{
  "a": {
    "c": 3,
    "d": 4
  },
  "arr": [
    {
      "x": 1,
      "y": 2
    },
    3
  ],
  "b": 1
}

Top-level only sort

Top-level keys are reordered to a, arr, b, while key order inside "a" stays as entered.

How to use

  1. Paste JSON into the input area.
  2. Choose scope (all levels/top level) and indentation.
  3. Click Sort and Format, then copy the output.

What You Can Do

  • Sort object keys ascending or descending
  • Choose all levels or top-level only
  • Keep array element order unchanged
  • Copy, download, and swap input/output

Specifications (Arrays, Nesting, Numeric Keys)

  • Object keys are sorted lexicographically, with selectable scope (all levels or top level only).
  • Array element order is preserved.
  • Indent options: 2 spaces, 4 spaces, tab, or minified one-line output.
  • If input is not valid JSON, an error is shown and output is not updated.
  • Integer-like keys may appear in numeric order depending on JavaScript property enumeration rules.

FAQ

Can nested objects be sorted too?

Yes. You can choose all levels or top level only.

What happens to arrays?

Array element order is preserved. Objects inside arrays are sorted depending on your selected scope.

Can I keep original indentation?

Input formatting is not preserved. Output is reformatted using your selected indentation style.

Does it support JSON5 comments or trailing commas?

No. This tool targets standard JSON only.

Where is data processed?

Everything runs locally in your browser. Your input is not sent to a server.

Related tools