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. NaN and Infinity are rejected.
  • No DOM references, no class instances — only JsonValue primitives.

Why it matters

  1. Snapshot tests compare strings, not deep-equal trees.
  2. Small, reviewable diffs per edit.
  3. 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.