Canonical JSON
Deterministic JSON serialization with keys sorted at every depth — the byte-for-byte stable form you hash or sign so two parties that build the same data produce the same bytes. stringifyJcs is strict RFC 8785 (JSON Canonicalization Scheme); stringify is a lenient variant that additionally serializes Buffers (as hex), Dates (ISO-8601), and BigInts (decimal) for the framework's own audit / config-drift fingerprints.
Both walks close the silent-data-loss class that ad-hoc Object.keys(...).sort() serializers fall into: Map / Set / RegExp / class instances, Symbols, functions, and circular references all throw a clean error rather than emitting {} or stack-overflowing. RFC 8785 strict mode additionally refuses BigInt / Buffer / Date (types JCS does not define) so the operator converts them to JSON-native shapes before signing.
Key ordering is V8's Object.keys(...).sort() — lexicographic UTF-16 code-unit order, which is exactly RFC 8785 §3.2.3 — and numbers are formatted by JSON.stringify, whose output is the ECMA-262 Number-to-string algorithm that RFC 8785 §3.2.2.3 references.
b.canonicalJson.stringify(value, opts?) #
{
bufferAs: string, // "hex" (default) | "reject" — Buffer / Uint8Array policy
}
Deterministic JSON with keys sorted at every depth — the lenient framework variant. Beyond JSON-native values it serializes Buffers / Uint8Arrays (hex), Dates (ISO-8601), and BigInts (decimal string); Map / Set / RegExp / class instances, Symbols, functions, and circular references throw rather than silently emitting {}. Use stringifyJcs for strict RFC 8785 interop.
b.canonicalJson.stringify({ b: 1, a: 2 });
// → '{"a":2,"b":1}'
b.canonicalJson.sortKeys(obj) #
The object's own keys in the framework's single canonical ordering — lexicographic UTF-16 code-unit sort (the same ordering the canonical serializers use). Returns an empty array for a non-object. Route fingerprint / report ordering through this rather than re-implementing the keys-then-sort dance inline.
b.canonicalJson.sortKeys({ b: 1, a: 2, c: 3 });
// → ["a", "b", "c"]
b.canonicalJson.stringifyJcs(value) #
Strict RFC 8785 JSON Canonicalization Scheme — the deterministic byte form to hash or sign when two parties must agree on the exact bytes (signed JSON credentials, receipts, deterministic request signing). Keys are sorted in UTF-16 code-unit order at every depth (§3.2.3) and numbers use the ECMAScript Number-to-string formatting §3.2.2.3 references. Inputs JCS does not define — BigInt, Buffer / Uint8Array, Date, Map, Set, RegExp, Symbol, function, and circular references — are refused, so the operator converts them to JSON-native shapes before signing rather than getting a silently lossy result.
b.canonicalJson.stringifyJcs({ "€": 1, "$": 2 });
// → '{"$":2,"€":1}' (keys sorted by UTF-16 code unit)
Last updated 2026-08-08T16:39:49.652Z by seeder.