DevKits

JSON Sorter — Sort Object Keys Alphabetically Online

Alphabetically sort JSON object keys online. Optional deep sort, ascending / descending, and Minified / 2-space / Tab output. Useful for canonical form, cleaner diffs, and deterministic hashes. 100% local.

Last updated:

197 chars · 11 lines
{
"author":"kuperwu"
"config":{
"cache":false
"targets":[
0:"web"
1:"cli"
]
"verbose":true
}
"keywords":[
0:"json"
1:"sort"
2:"canonical"
]
"name":"DevKits"
"version":1
}

Paste JSON to reorder every object's keys alphabetically. Optional deep sort recurses into nested objects; array element order is preserved. Useful for canonical form, deterministic diffs, and stable content hashes.

What is JSON Sort?

Sorting the keys of a JSON object gives you a canonical (deterministic) representation that makes diffs dramatically smaller and lets you fingerprint content by hashing the serialized form. The technique matters wherever two different processes serialize 'the same' JSON but do so with different key orders — a common source of noise in code review, replication logs, and cache keys. This tool sorts keys with UTF-16 code-point ordering (the JS default, matching Python / Go / Java / RFC 8785) so results are portable across runtimes. Values are left untouched; array element order is preserved because it is semantically meaningful.

How to alphabetize JSON keys

  1. 1Paste your JSON into the input editor.
  2. 2Choose direction (A → Z or Z → A) and toggle 'Sort nested objects' for deep vs. shallow behavior.
  3. 3The output pane instantly shows the sorted JSON — pretty-printed or minified based on the indent setting.
  4. 4Copy the sorted JSON, or feed it through a hash function to fingerprint the content.

Tips & Best Practices

  • For strict RFC 8785 canonical JSON (used for signing), use a dedicated library — this tool covers key order but not the full number-normalization rules.
  • Sorting is useful before diffing two JSON files in a code review — reordered keys otherwise create noisy diffs even when nothing semantic changed.
  • Combine sort + minify to produce a stable content hash: JSON.stringify(sort(JSON.parse(input))) — identical inputs always hash to identical bytes.

Frequently Asked Questions

Why sort JSON keys?

Sorted keys give you a canonical form that makes diffs shrink dramatically (the same logical change no longer moves neighboring keys around), and it lets you hash two JSON documents and compare — a common trick for detecting content changes.

Does it sort array elements too?

No. Arrays are ordered by definition — sorting their elements would change semantics. Only object keys are sorted. If you want to sort by a specific field inside array elements, use jq or a small script.

Is this the same as RFC 8785 canonical JSON?

Close but not identical. RFC 8785 (JCS — JSON Canonicalization Scheme) also mandates a specific number serialization and UTF-16 code-point key ordering. This tool matches JCS on key order and uses JSON.stringify for values, which is equivalent for common cases (integers within safe range, standard strings). For full JCS compliance use a dedicated library.

How are Unicode keys sorted?

By UTF-16 code point (the default of JavaScript's < / > operators on strings). This matches Python, Go, and Java default string comparison and RFC 8785. If you need a locale-aware sort, post-process the output.

Related Tools