esc

Sort JSON Keys Online

Sort JSON object keys alphabetically — recursively, in natural or case-insensitive order, with pinned keys. Numbers and strings stay exactly as written.

Order
Options
Indent
Comma-separated · exact, case-sensitive match
0 B
Sorted output
Sorted JSON will appear here.
Waiting for input — lines —
Guide

How to sort JSON keys

Paste a JSON document into the input pane. The tool parses it as strict JSON and prints the same document with every object's keys in sorted order. Pick the direction, indentation and options in the toolbar — the output updates as you type.

Only the order of keys , whitespace and line breaks change. String and number literals are copied from your input character by character, so large integers such as 9007199254740993, trailing zeros like 1.2300 and exponents like 1e400 survive intact. A regular JSON.parse / JSON.stringify round-trip would silently round or rewrite them.

Example

Input:

{"name":"api","id":7,"limits":{"burst":20,"rate":100}}

Output with default options and id pinned first:

{
  "id": 7,
  "limits": {
    "burst": 20,
    "rate": 100
  },
  "name": "api"
}
Options

Sort options explained

Order: A→Z and Z→A

The default order compares keys by UTF-16 code units, the same way JavaScript compares strings with <. It does not depend on your browser locale, so the result is identical on every machine: "1", "10", "2", "A", "a", "b". Z→A reverses the order of all keys that are not pinned.

Recursive

When enabled, nested objects are sorted too, including objects inside arrays. Turn it off to reorder only the top-level object and leave everything below untouched.

Natural

Natural (numeric) sorting compares runs of digits by their value, so item2 comes before item10 . Signs, dots and exponents have no numeric meaning — only plain ASCII digits are compared as numbers.

Ignore case

Compares lower-cased keys, so Name and name sit next to each other. "A" and "a" remain two different keys; when they tie, the original strings decide, so the output never depends on the input order.

Pinned keys

Pinned keys are placed first in every sorted object, in the order you list them. It's a common convention to keep id, name or type at the top. Pinned keys that don't exist in an object are ignored.

Use cases

When to sort JSON

  • Cleaner diffs. Two API responses or config files with the same data but a different key order become directly comparable.
  • Stable fixtures and snapshots. Keep test fixtures and package.json-style files in one canonical order so code reviews show real changes only.
  • Readable configs. Alphabetical keys make large configuration objects, translations and feature-flag files easier to scan.
  • Deterministic output. The same input and options always produce byte-for-byte the same text, which helps caching and change detection.
Troubleshooting

Errors and limitations

  • Invalid JSON — comments, trailing commas, single quotes and unquoted keys are not allowed. The error shows the exact line and column. Run the document through the JSON Formatter & Validator first if you need more context.
  • Duplicate key — the same key appears twice in one object. Most parsers silently keep the last value; this tool reports it with the key path so you can fix the source.
  • Arrays keep their order. Element order in an array is usually meaningful, so only object keys are reordered.
  • Not canonical JSON. The output is not RFC 8785 (JCS): 1 and 1.0 or "é" and "\u00e9" stay different. Don't use it as the input for cryptographic signatures.

The sorting engine is the open-source @helpers-work/json-sort library, which also ships a CLI with a --check mode for CI pipelines.

FAQ

Frequently asked questions

Is my JSON uploaded to a server?

No. Sorting runs entirely in your browser with the open-source @helpers-work/json-sort library. The JSON you paste never leaves your device.

Does sorting change my numbers or strings?

No. Number and string literals are copied exactly as written, so values like 9007199254740993, 1.2300 or 1e400 stay unchanged. Only key order, whitespace and line breaks change.

Are arrays sorted too?

No. Array order is usually meaningful, so array elements keep their original order. Objects inside arrays are still sorted when recursive sorting is enabled.

What is natural (numeric) sorting?

With natural sorting, runs of digits are compared by value, so "item2" comes before "item10". Without it, keys are compared character by character and "item10" comes first.

Why does the tool reject JSON that my browser accepts?

The sorter is strict: duplicate keys, comments and trailing commas are errors. Duplicate keys are rejected because JSON.parse silently keeps only the last value, which can hide real bugs.

Can I use the output for signatures or hashing?

Only with care. The output is deterministic for the same input and options, but it is not RFC 8785 canonical JSON: 1 and 1.0 stay different. Use a JCS implementation for cryptographic signatures.