Canonical JSON
A stable representation for documents and transactions.
SpineEditor emits documents, transaction JSON, and trace artifacts in a canonical JSON form. Semantically equal values serialize to byte-identical JSON strings.
What canonical means
- Key order is fixed within each object by schema, not alphabetical sort.
- Numbers are normalized.
NaNandInfinityare rejected. - No DOM references, no class instances — only
JsonValueprimitives.
Why it matters
- Snapshot tests compare strings, not deep-equal trees.
- Small, reviewable diffs per edit.
- Two producers that agree on canonical JSON agree on document identity.
Implementation
The canonical helpers live in @spine-editor/core: canonical.ts, transaction-json.ts, schema/schema-json.ts, doc/doc-json.ts. They are pure functions — no wall-clock time, no random IDs, no environment reads.