Skip to main content

canonical_json

Function canonical_json 

Source
pub fn canonical_json(value: &Value) -> Value
Expand description

One rendering per JSON value, for everything in this contract that identifies something by hashing it.

Object keys are sorted, and a whole number is folded onto one spelling. Both exist because the hash is taken over rendered text: serde_json keeps the variant it parsed, so 1, 1.0 and 1e0 arrive as PosInt and Float and Display renders the variant rather than the value. Two producers of the same logical configuration – or two versions of one producer’s serializer – would otherwise hash differently.

Shared rather than copied: the embedding-space identity and the ingest request hash both do this, and the first version of this function lived in two places and was fixed in one.