| Crates.io | serde_canonical_json |
| lib.rs | serde_canonical_json |
| version | 1.0.0 |
| created_at | 2023-03-07 21:39:34.291602+00 |
| updated_at | 2023-03-07 21:39:34.291602+00 |
| description | Implements a CanonicalFormatter for serde_json |
| homepage | https://github.com/gelvinp/rs-serde_canonical_json |
| repository | https://github.com/gelvinp/rs-serde_canonical_json |
| max_upload_size | |
| id | 803963 |
| size | 26,898 |
This crate provides a Canonical JSON formatter for serde_json.
use serde::Serialize;
use serde_json::Serializer;
use serde_canonical_json::CanonicalFormatter;
#[derive(Serialize)]
struct Data
{
c: isize,
b: bool,
a: String,
}
fn main()
{
let data = Data { c: 120, b: false, a: "Hello!".to_owned() };
let mut ser = Serializer::with_formatter(Vec::new(), CanonicalFormatter::new());
data.serialize(&mut ser).expect("Failed to serialize");
let json = String::from_utf8(ser.into_inner()).expect("Failed to convert buffer to string");
assert_eq!(json, r#"{"a":"Hello!","b":false,"c":120}"#);
}