Skip to main content

stable_repr

Function stable_repr 

Source
pub(super) fn stable_repr(v: &Value) -> String
Expand description

Produce a deterministic string representation of a serde_json::Value suitable for stable hashing.

Object keys are sorted recursively so that {"b":2,"a":1} and {"a":1,"b":2} produce identical output. Array element order is preserved. Recursion is capped at MAX_REPR_DEPTH to prevent stack overflow on adversarially nested inputs; values beyond that depth are replaced with the sentinel "...", which means two deeply-nested values that differ only below depth 16 will hash identically.

The output is not valid JSON — it is intentionally compact and only used as a pre-image for FNV-1a; never parsed or returned to callers.