JSON Canonicalization & Hash
Produce the RFC 8785 canonical form of a JSON document — the invariant byte sequence you hash or sign — and its digest. Nothing leaves your browser, which matters when the document is about to be signed.
Canonical form will appear here
Canonicalization can change your data before you sign it
RFC 8785 builds on ECMAScript number serialization and constrains input to I-JSON (RFC 7493). That has a consequence worth understanding before you rely on a signature:
you send {"id":9223372036854775807,"amount":0.1}
canonical {"amount":0.1,"id":9223372036854776000}
The identifier is rounded, because it needs more precision than an IEEE 754 double provides. A signature over the canonical form does not cover the number you actually sent. This tool detects that case and every other value that changes, and tells you — rather than quietly handing you a hash of different data. If you must sign large identifiers, carry them as strings.
Duplicate member names are the other trap.
I-JSON forbids them, and JSON.parse silently discards one of the values. We scan the source
text before parsing, so the duplicate is reported instead of vanishing.
The four rules
Whitespace removed
RFC 8785 §3.2.1. No insignificant whitespace anywhere in the output.
Properties sorted
§3.2.3, by UTF-16 code unit — so A sorts before a, and
astral characters sort by their surrogate values rather than their code points.
Primitives serialized as ECMAScript does
§3.2.2. 1e2 becomes 100, 1.0 becomes 1.
The spec reuses ECMA-262 rather than defining its own number format.
UTF-8 output
§3.2.4. The byte count shown next to the output is the length you hash, not the character count.
Specifications
- RFC 8785 — JSON Canonicalization Scheme (JCS) — A. Rundgren, B. Jordan, S. Erdtman, June 2020. Independent Submission, Informational. §3.2 Generation of Canonical JSON Data.
- RFC 7493 — The I-JSON Message Format — T. Bray, Ed., 2015. Standards Track. The subset RFC 8785 requires: unique member names and numbers within the IEEE 754 double range.
- RFC 8259 (STD 90) §6 — Numbers
— names
1E400and3.141592653589793238462643383279as exactly the interoperability problem this tool warns about, and states that integers within ±(2⁵³−1) are interoperable. - ECMA-262 — ECMAScript Language Specification — Ecma International. Supplies the number and string serialization RFC 8785 §3.2.2 builds on.
Verified against the official RFC 8785 test vectors — 6/6 on both the canonical text and the UTF-8 byte output.
Signing a document you also need to update? See the JSON Patch tool and when Merge Patch cannot do the job.