Skip to main content

Module jcs

Module jcs 

Source
Expand description

RFC 8785 — JSON Canonicalization Scheme (JCS).

Rules implemented (and tested against the RFC’s own vectors):

  • object keys sorted by UTF-16 code units (surrogate order, not byte order — they differ for supplementary-plane characters);
  • numbers serialized with ECMAScript ToString(Number) semantics (shortest round-trip digits; decimal notation for exponents in (-7, 21); e+/e- exponential outside; -00);
  • strings minimally escaped (\", \\, \b, \f, \n, \r, \t, \u00XX for other controls; everything else literal UTF-8);
  • no insignificant whitespace.

Integers beyond ±2^53 are rejected (not silently rounded): JCS numbers are IEEE-754 doubles and precision loss would corrupt canonical hashes (silent-error class D13.4).

Enums§

JcsError
Canonicalization failures.

Functions§

canonicalize
Canonicalize a JSON value per RFC 8785. Returns the canonical UTF-8 string.