Expand description
Canonical JSON: parse, then re-serialize compact with object keys sorted.
serde_json::Map is a BTreeMap here (the preserve_order feature is off), so a
parsed value re-serializes with sorted keys and no whitespace. NaN / Infinity
are rejected by the parser and cannot exist inside a Value, so a canonical form is
always valid JSON.
Numbers round-trip exactly within i64 / u64; larger integers become f64 and
canonicalize to their shortest round-trip form. Canonicalization is idempotent:
canonicalize(canonicalize(x)) == canonicalize(x).
Functionsยง
- canonical_
of - Canonical form of any serializable value. Goes through
Valueon purpose: struct serialization emits fields in declaration order,Valueemits them sorted. - canonicalize
- Parse
rawand return its canonical form. - parse
- Parse JSON text into a
Value;malformed_jsonwhen it is not valid JSON. - to_
string - Serialize a
Valuecompact with object keys sorted.