diff --git a/wizard-work/beam/json_canonical.py b/wizard-work/beam/json_canonical.py index 5998392..4699aa6 100644 --- a/wizard-work/beam/json_canonical.py +++ b/wizard-work/beam/json_canonical.py @@ -1,5 +1,17 @@ -"""Canonical JSON serialization (RFC 8785-ish): sorted keys, compact separators, -no NaN/Infinity, deterministic float repr, UTF-8, ensure_ascii=False.""" +"""Canonical JSON serialization: sorted keys, compact separators, no NaN/Infinity, +deterministic float repr, UTF-8, ensure_ascii=False. + +NOT RFC 8785 (JCS), and not claimed to be. JCS is IEEE-754 double-based with its +own number grammar; this module emits Python's `repr` for floats and passes int +through unchanged. Three measured divergences from RFC 8785 Table 1: + + -0.0 -> "-0.0" (JCS: "0") + 1e-06 -> "1e-06" (JCS: "0.000001") + 2**53+1 -> "9007199254740993" (JCS max positive integer: 9007199254740992) + +Key order is `sort_keys=True`, i.e. by Unicode code point; JCS sorts by UTF-16 +code unit, so the two diverge above U+FFFF. +""" from __future__ import annotations import json import math