Dev TooloraLocal dev tools

> Formatters

JSON Sort Keys & Canonicalize

Sort JSON object keys recursively, or produce the RFC 8785 canonical form used for signing and hashing.

Runs locallyWorks offline
Back to results
Input

Source data

Mode
Order
Output

Result

Your result will appear here.

Tool guide

About this tool.

Sort keys rewrites a JSON document so every object lists its keys in order, recursively. Arrays keep their item order, because the order of array items carries meaning.

Canonical mode produces the JSON Canonicalization Scheme from RFC 8785 (JCS). The output has no whitespace, keys sorted by UTF-16 code units, strings escaped the way ECMAScript escapes them and numbers written in the shortest ECMAScript form. Two systems that canonicalize equal data get byte-identical text.

Keys are compared by UTF-16 code units, not by locale. Uppercase letters sort before lowercase ones, and characters outside the Basic Multilingual Plane sort by their surrogate pairs.

  • Sign or hash a JSON payload so the signature does not depend on key order or formatting.
  • Compare two documents byte for byte after sorting their keys.
  • Keep configuration files and fixtures stable so diffs show only real changes.
  • Check what a verifier will see before you feed JSON into the Hash or HMAC tool.

Paste JSON and choose Sort keys or Canonical. Sort keys keeps the document readable and lets you pick ascending or descending order and the indentation.

Canonical mode ignores order and indentation and returns compact RFC 8785 text. The summary shows its size in UTF-8 bytes, which is the length a signature or hash covers.

Both modes parse the input as JSON first, so comments, trailing commas and single quotes are rejected with an error.

Use Sort keys for diffs and review, and Canonical for signing, hashing and cache keys.

  • {"b":1,"a":{"d":[2,1],"c":"é"}} canonical → {"a":{"c":"é","d":[2,1]},"b":1}.
  • [1E30, 4.50, 2e-3, -0] canonical → [1e+30,4.5,0.002,0].
  • {"z":1,"é":2,"a":3} sorted ascending → keys a, z, é.
  • {"a":1,"b":2} sorted descending → keys b, a.
  • {"b":[{"y":1,"x":2}]} sorted → the array stays in place, only the inner keys are sorted.

  • Runs locally and offline; the input is never uploaded.
  • Nesting is limited to 64 levels; deeper input is rejected, not truncated.
  • Canonical mode reads numbers as IEEE-754 doubles, as RFC 8785 requires, so integers outside ±9,007,199,254,740,991 are rounded. Sort keys mode rejects them instead; quote them as strings to keep their exact digits.
  • Duplicate keys in the input collapse to the last value, because the JSON parser keeps only one.
  • A number beyond the range of a double, such as 1e400, or one that would become 0, such as 1e-400, is rejected in both modes. Canonical mode also rejects a string with an unpaired surrogate, as RFC 8785 requires.

FAQ

Questions about JSON Sort Keys & Canonicalize

What is JCS?

JCS is the JSON Canonicalization Scheme from RFC 8785. It defines one exact text form for any JSON value, so signatures and hashes of equal data always match.

Why does 1E30 change?

JCS writes numbers the way ECMAScript does, so 1E30 becomes 1e+30 and 4.50 becomes 4.5. The value is the same IEEE-754 double, only its text form is fixed.

Why canonicalize before signing or hashing?

A signature or hash covers bytes, not meaning. Two equal documents with different key order or spacing would produce different digests. Canonical text removes that difference before you sign or hash.

Why do arrays stay in their order?

Array order is data: [1,2] and [2,1] are different values. Only object keys have no defined order, so only they are sorted.

Continue with

JSON FormatFormat, minify or validate JSON without rounding numbers, rewriting strings or dropping duplicate keys.JSON Flatten & UnflattenFlatten nested JSON into path keys with dot or bracket notation, or rebuild nested JSON from flat keys.Hash GeneratorHash exact UTF-8 text or local file bytes with SHA-256, SHA-512, SHA-1 or MD5.HMAC GeneratorGenerate a keyed message digest from exact UTF-8 text and a local secret.