Canonical JSON
Canonical JSON is a deterministic serialization of JSON objects where key order, whitespace, and number formatting follow fixed rules. Two logically equal objects produce identical byte strings, which is required for cryptographic signatures, webhook verification, and cache keys that must not change with pretty-printing.
Technical Architecture & Deep-Dive
Plain JSON allows flexible key order and spacing, so the same data can hash differently. Canonicalization sorts keys lexicographically, omits insignificant whitespace, and normalizes numbers so HMAC or RSA signatures remain stable.
Edge gateways computing signatures for outbound webhooks or validating provider callbacks should canonicalize bodies before hashing, independent of how the client originally formatted JSON.
Key Architectural Benefits
Implement Canonical JSON at the Edge
Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.
Frequently Asked Questions
Q:Is canonical JSON a web standard?
Several specs define canonical forms for JWS and similar protocols. Teams should follow the exact rules their signature algorithm documents.
Related Architecture Concepts
JSON Schema is a declarative vocabulary for describing the structure of JSON data. A schema defines expected properties, data types, required fields, and value constraints, allowing tools to validate payloads, generate documentation, and produce typed client code automatically.
HMAC authentication uses a hash-based message authentication code, computed from a message and a shared secret key, to prove that a request came from a holder of the secret and was not modified. The receiver recomputes the HMAC and compares it to the value sent.
Webhook signature verification is validating that an incoming webhook was sent by the expected provider and was not altered. Providers sign each payload with a shared secret, typically using HMAC-SHA256, and your endpoint recomputes the signature and compares it before trusting the event.