Tools > JSONJSON Key Sorter
Input
Output
Valid JSONNo
Keys sorted0
Depth0

JSON Key Sorter Online — Sort JSON Keys Alphabetically, Reverse & Custom Order

Need to sort the keys in your JSON objects for consistent formatting, easier diffing, or cleaner version control? This free tool sorts all object keys at every nesting level, producing deterministic, canonical JSON output. Choose ascending, descending, natural, or custom key ordering — all processed in your browser.

How to Use This Tool

  1. Paste your JSONPaste a JSON object or array into the input panel. The tool accepts any valid JSON.
  2. Choose sort orderSelect Ascending (A→Z) for alphabetical, Descending (Z→A) for reverse, Natural for numeric-aware sorting (key2 before key10), or Custom to specify priority keys.
  3. Set sort depthChoose "All levels" to sort keys at every nesting depth, "Top level only" for the root object, or "Custom depth" to sort up to N levels deep.
  4. Configure additional optionsToggle case sensitivity for strict lexicographic order, enable array sorting to reorder arrays of objects by a key value, and choose your preferred indentation style.
  5. Copy the resultThe sorted JSON appears instantly in the output panel. Click Copy to use it in your project.
  6. Chain with other toolsWith Auto-fill enabled, your output automatically carries over when you open another tool from the sidebar. Use the back and forward arrows to navigate between tools.

Features

Four Sort Orders

Ascending (A→Z), Descending (Z→A), Natural (numeric-aware where key2 comes before key10), and Custom (user-defined priority keys).

Recursive Depth Control

Sort keys at all nesting levels, only the top level, or up to a custom depth. Nested objects beyond the limit keep their original key order.

Custom Key Priority

Specify a comma-separated list of keys that should appear first (e.g. id, name, type). Remaining keys are sorted alphabetically after the priority keys.

Natural Sorting

Numeric-aware sorting where key2 comes before key10. Essential for configuration files with numbered keys.

Array of Objects Sorting

Optionally sort arrays whose elements are all objects by a specified key value. Great for normalizing lists of records.

Complete Privacy

All processing runs in your browser. Your JSON data never leaves your device — no server requests, no storage.

Real-World Use Cases

1

Normalize configuration files

Sort keys in package.json, tsconfig.json, or .eslintrc to maintain a consistent, canonical key order across your team. Reduces merge conflicts and makes code reviews easier.

2

Diff-friendly JSON output

When JSON keys are sorted deterministically, git diffs show only actual value changes — not key reordering. Essential for configuration files stored in version control.

3

Normalize API responses

Sort keys in API response payloads before comparing them. Ensures two equivalent JSON responses with different key orders are recognized as identical.

4

Clean up database exports

Sort keys in exported JSON documents from MongoDB, CouchDB, or other document databases. Makes large exports more readable and consistent.

5

Enforce schema ordering

Use custom key order to enforce a canonical structure like id → name → type → description in JSON schemas, API definitions, or data models.

Frequently Asked Questions

What is natural sort order?
Natural sort treats numeric parts of keys as numbers rather than text. So key2 sorts before key10 (because 2 < 10), unlike strict alphabetical sort where key10 comes before key2 (because '1' < '2').
How does custom key order work?
Enter a comma-separated list of key names (e.g. id, name, type, description). These keys appear first in the specified order. All remaining keys are sorted alphabetically after the priority list.
What does sort depth control?
Sort depth determines how deep into nested objects the sorter goes. 'All levels' sorts recursively everywhere. 'Top level only' sorts just the root object. 'Custom depth' lets you set a specific level — depth 2 sorts root and first-level nested objects, leaving deeper nesting untouched.
Does sorting change my JSON values?
No. Only the key order within objects changes. All values, arrays, nested structures, and data types remain exactly the same. The output is semantically identical to the input.
How does case sensitivity affect sorting?
With case sensitivity off (default), 'Apple' and 'apple' are treated as equivalent for sorting purposes. With it on, uppercase letters sort before lowercase in ascending order (strict lexicographic/ASCII order).
Is my JSON data sent to a server?
No. All processing happens entirely in your browser using JavaScript. Your data is never transmitted or stored anywhere.

Related Tools