🔤 JSON Sort

Sort JSON object keys alphabetically — or apply a preset (package.json, tsconfig.json, composer.json) — recursively, instantly in your browser.

About JSON Sort

Sort every key in a JSON object alphabetically — A→Z or Z→A — recursively through nested objects. Or pick a preset for a known file shape (package.json, tsconfig.json, composer.json) to apply the canonical field order developers expect for that file. Useful for canonicalizing config files, producing line-stable diffs, or comparing objects whose keys arrived in a different order.

How to use

  1. Paste your JSON into the input.
  2. Pick a preset, or leave it on Alphabetical.
  3. Choose the sort direction for any extra keys (A→Z or Z→A).
  4. Copy the canonicalized output to your clipboard.

Presets

  • Alphabetical — deep sort by key name; the A→Z / Z→A toggle controls direction.
  • package.json (npm) — full sort-package-json field order, script :-namespace grouping with pre/post kept next to their main, alpha-sorted dependency blocks, and exports with default last.
  • tsconfig.json$schema, extends, compilerOptions, include, exclude, files, references in canonical order.
  • composer.json — PHP package manifest layout (name, require, require-dev, autoload, …) with require-like maps alpha-sorted.

Tips

  • Arrays keep their original order — only object keys are sorted.
  • Sorting is recursive, so the entire tree is canonicalized in one pass.
  • With a preset, A→Z / Z→A only controls how any extra keys (not in the preset) are sorted at the end.
  • The output is strict JSON; trailing commas or comments in the input are dropped.

FAQ

Will it sort arrays too?
No. Only object keys are sorted; arrays preserve their original order, since array order is usually meaningful.
Does the output stay valid JSON?
Yes. Lenient input quirks like trailing commas or comments are dropped; the output is always strict JSON.
Why would I sort JSON keys?
It produces canonical output for line-stable git diffs, repeatable fingerprints, and easier visual comparison of objects with the same shape.
Is sorting recursive?
Yes. Every nested object in the tree is sorted in one pass.
What does the package.json preset do differently?
It applies the same field order as keithamus/sort-package-json: known keys (name, version, description, …, scripts, dependencies, devDependencies, …) follow a fixed sequence; scripts are grouped by `:` namespace with pre/post variants kept next to their main script; dependencies blocks are alpha-sorted (locale-aware); the `exports` field puts path keys first and `default` last. Any unknown top-level keys are appended after, with private (leading `_`) keys at the very end.
How do A→Z / Z→A interact with a preset?
The preset fixes the order of its known keys. A→Z and Z→A only control how any extra keys you have that aren't part of the preset are sorted at the end.

More tools

JSON

Code

Ornaments

Image

Audio

Web / SEO

Generators

PDF

Time