JSON Sort Keys
Reorders the keys of a JSON object in alphabetic order, with optional recursive descent into nested objects and arrays of objects. Arrays themselves are left in their original order — only object key order changes. Useful for deterministic diffs (committing a sorted `package.json` so reviewers see only meaningful changes), normalizing API fixtures before snapshot testing, or matching the expected order in a downstream tool that's strict about key order.
Sorted
{
"author": {
"email": "demo@example.com",
"name": "Alice"
},
"dependencies": {
"astro": "^4",
"react": "^18"
},
"name": "demo",
"scripts": {
"build": "astro build",
"dev": "astro dev",
"test": "vitest"
},
"version": "1.0.0"
}Only object keys are reordered. Array element order is preserved — sort those separately if needed.
How to use
- Paste your JSON (a `package.json` or any object).
- Toggle `deep` to sort nested objects too, or leave it off to sort only top-level keys.
- Pick ascending or descending order and copy the result.
Frequently asked questions
- Does this re-order array elements?
- No — only object keys. Arrays keep their original order because element position is usually meaningful. If you also need array elements sorted, run a dedicated sort step (jq `sort_by`, for example) first.
- Why would I sort `package.json`?
- Tools like `npm` are tolerant of key order, but humans aren't. Sorting keeps reviewers focused on real changes (a new dependency) instead of churn from `npm install` reshuffling. Some teams enforce this via a `sort-package-json` pre-commit hook.
- Is the sort locale-aware?
- No — it's a code-point sort with optional case-insensitive folding. That matches what `jq`, `Object.keys().sort()`, and most language standard libraries do by default. Locale collation can give different results for non-ASCII keys, but is rarely what you want for canonical output.
- What about JSON5 / comments / trailing commas?
- Strict JSON only — the input must parse via `JSON.parse`. If you have a config file with comments, strip them first or use a JSON5 parser before pasting in.
Related tools
JSON Flatten / Unflatten (Dot Notation)
Flatten nested JSON into single-level dot-notation keys, or rebuild nested JSON from flat keys — with configurable delimiter and array notation, fully reversible in your browser.
UUID v5 Generator
Generate a deterministic, namespace-based UUID (version 5, SHA-1) from a namespace and a name — the same inputs always produce the same UUID.
JSON Formatter & Validator
Format, beautify, minify, and validate JSON right in your browser.
JWT Decoder
Decode a JSON Web Token to inspect its header, claims, and expiration.
JSON Diff
Compare two JSON documents structurally — see exactly which keys were added, removed, or changed.
JSON → TypeScript Interface
Generate TypeScript interfaces from any JSON sample — types are inferred recursively and named after each key.