json_canon/
lib.rs

1//! # `json-canon`
2//!
3//! Serialize JSON into a canonical format.
4//!
5//! Safe for generating a consistent cryptographic hash or signature across platforms.
6//!
7//! Follows [RFC8785: JSON Canonicalization Scheme (JCS)]
8//!
9//! [RFC8785: JSON Canonicalization Scheme (JCS)]: https://tools.ietf.org/html/rfc8785
10//!
11//! ## Example
12//!
13//! ```rust
14//! use json_canon::to_string;
15//! use serde_json::json;
16//! # use serde_json::Error;
17//! # fn main() -> Result<(), Error> {
18//!
19//! let data = json!({
20//!     "from_account": "543 232 625-3",
21//!     "to_account": "321 567 636-4",
22//!     "amount": 500,
23//!     "currency": "USD"
24//! });
25//!
26//! println!("{}", to_string(&data)?);
27//! // {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! ## Caveats
33//!
34//! `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"`.
35//!
36
37mod object;
38mod ser;
39
40pub use self::ser::{to_string, to_vec, to_writer};