Waiting for JSON content
Start typing on the left or load one of the sample payloads to inspect it instantly.
Instantly clean, validate, and inspect web payloads
Start typing on the left or load one of the sample payloads to inspect it instantly.
Instantly sort JSON keys alphabetically (A→Z or Z→A), recursively through every nested object. Values, data types, and array order stay intact — 100% in-browser, with zero data upload.
Every tool runs in your browser, so the JSON you paste never leaves your device.
Formatting, minifying, repairing, and the tree view all run on your device, so there are no uploads to wait on.
Syntax errors like unescaped quotes and trailing commas are flagged with their exact line and column.
How alphabetical key ordering produces stable, diff-friendly JSON while preserving values, data types, and array element order.
JSON objects are unordered collections of name/value pairs per RFC 8259 §4, which means serializers in different languages and runtimes emit keys in different orders. This non-determinism creates noisy version-control diffs: two logically identical configuration files can show dozens of "changed" lines simply because key order shifted. Sorting object keys alphabetically produces a canonical, deterministic representation so that re-serialized API responses, database exports, and config files diff cleanly. PrettyJSON's sorter recursively orders keys at every nesting depth while leaving values and array element sequences untouched, guaranteeing the data remains semantically identical to the input.
The sorter performs a depth-first recursive traversal of the parsed JSON tree. At each object node, keys are extracted, sorted using lexicographic string comparison (locale-aware), and rebuilt into a new object in the chosen direction — ascending (A→Z) or descending (Z→A). Array nodes are traversed element-by-element so that nested objects inside arrays are sorted too, but the array's own element order is intentionally preserved because array order is semantically meaningful in JSON. Primitive values (strings, numbers, booleans, null) are returned unchanged. This composition sorts arbitrarily deep structures in a single linear pass.
// Input (unsorted keys)
{
"name": "Alice",
"age": 30,
"address": {
"zip": "10001",
"city": "NYC"
}
}
// Output (keys sorted A → Z, recursively)
{
"address": {
"city": "NYC",
"zip": "10001"
},
"age": 30,
"name": "Alice"
}Sorted JSON keys are valuable well beyond readability. Snapshot testing frameworks compare serialized JSON, and canonical key ordering prevents flaky test failures. Content-addressable caching and hashing (e.g., generating an ETag or cache key from a payload) require a stable byte representation — sorting keys before hashing ensures identical data always yields the same hash. Teams that commit JSON config files (package manifests, i18n translation catalogs, infrastructure descriptors) use key sorting to keep pull-request diffs minimal and review-friendly. PrettyJSON runs the entire sort in your browser, so even sensitive production payloads never leave your machine.
Common questions and expert answers regarding this tool.
It reorders the keys of every object in your JSON alphabetically — either ascending (A→Z) or descending (Z→A) — recursively through all nested objects. Values, data types, and the order of array elements are preserved exactly.
No. Sorting only reorders object keys, which are unordered by definition in RFC 8259 §4. The resulting JSON is semantically identical to the input — same values, same types, same array order.
Canonical key ordering produces clean, deterministic output. It minimizes version-control diffs on config files, stabilizes snapshot tests, and enables consistent content hashing for cache keys and ETags.