Architecture Decision Record

ADR-0036: Canonical JSON Serialization for Object Payloads

Status: Accepted · Date: 2026-03-06

Status: Accepted

Date: 2026-03-06

Context

BSFG facts carry structured payloads in object_json. Because the boundary model relies on idempotent append keyed by message_id, the system must be able to determine whether two messages with the same identifier are truly identical.

Standard JSON does not guarantee deterministic byte representation: object key order, whitespace, and number formatting may vary across languages and runtimes. The JSON Canonicalization Scheme (JCS) addresses this by defining a deterministic serialization of JSON data that can be hashed or compared consistently across systems. ([rfc-editor.org](https://www.rfc-editor.org/rfc/rfc8785?utm\_source=chatgpt.com))

The architecture therefore needs to decide whether payload equality is evaluated at the semantic object level or the byte-representation level.

Options Considered

Option Description Benefits Drawbacks
Opaque byte comparison Accept whatever JSON encoding the producer sends and compare raw bytes.

|

| | Loose semantic comparison | Parse JSON into objects and compare structures ignoring order and formatting. |

|

| | Binary serialization format | Replace JSON entirely with a binary protocol format. |

|

| | Canonical JSON serialization (Selected) | Require canonical JSON encoding so that equivalent objects produce identical byte representation. |

|

|

Decision

BSFG requires canonical JSON serialization for object_json.

object_json = canonicalized JSON (RFC 8785)

Canonicalization ensures:

Equality checks during idempotent append are therefore performed on the canonical byte representation of the JSON payload.

hash = SHA256(canonical_json(object))

This hash may be used internally to verify that repeated attempts with the same message_id contain identical content.

Consequences

Benefits:

Tradeoffs: