pub fn canonical_json(value: &Value) -> Result<String, CanonicalJsonError>Expand description
The RFC 8785 canonical form of value.
Members are sorted by their UTF-16 code units and written without whitespace, so any implementation that reads the same value writes the same bytes.
use rite_model::canonical_json;
use serde_json::json;
let value = json!({ "b": 2, "a": [true, null, "x"] });
assert_eq!(canonical_json(&value)?, r#"{"a":[true,null,"x"],"b":2}"#);
assert!(canonical_json(&json!({ "ratio": 1.5 })).is_err());§Errors
Returns CanonicalJsonError for a non-integer number or an integer
beyond ±(2^53 - 1).