Crate json_canon

source ·
Expand description

json-canon

Serialize JSON into a canonical format.

Safe for generating a consistent cryptographic hash or signature across platforms.

Follows RFC8785: JSON Canonicalization Scheme (JCS)

Example

use json_canon::to_string;
use serde_json::json;

let data = json!({
    "from_account": "543 232 625-3",
    "to_account": "321 567 636-4",
    "amount": 500,
    "currency": "USD"
});

println!("{}", to_string(&data)?);
// {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}

Caveats

serde_json deserializes f64::NAN and f64::Infinite as None, so if given a Rust struct with these values, the json-canon will currently output "null".

Functions

  • Serialize the given value as a String of JSON.
  • Serialize the given value as a JSON byte vector.
  • Serialize the given value as JSON into the IO stream.