Skip to main content

canonical_json

Function canonical_json 

Source
pub fn canonical_json(value: &Value) -> Vec<u8> ⓘ
Expand description

The canonical bytes of a JSON value: object keys sorted at every depth, no whitespace. Signer and verifier compute it identically regardless of how either parser orders keys.

use majordomus_cli::mesh::journal::canonical_json;
let a = serde_json::json!({"b": 1, "a": [{"d": 2, "c": 3}]});
assert_eq!(canonical_json(&a), br#"{"a":[{"c":3,"d":2}],"b":1}"#.to_vec());