#canonical-json #serde-json #canon #json

canon-json

serde_json Formatter to serialize as RFC 8785 canonical JSON

2 releases

0.2.1 Jun 23, 2025
0.2.0 Jun 17, 2025

#415 in Encoding

Download history 2056/week @ 2025-07-05 4055/week @ 2025-07-12 3293/week @ 2025-07-19 4155/week @ 2025-07-26 5729/week @ 2025-08-02 3387/week @ 2025-08-09 3150/week @ 2025-08-16 4555/week @ 2025-08-23 3746/week @ 2025-08-30 5562/week @ 2025-09-06 4149/week @ 2025-09-13 4522/week @ 2025-09-20 3691/week @ 2025-09-27 2861/week @ 2025-10-04 4389/week @ 2025-10-11 3842/week @ 2025-10-18

15,394 downloads per month
Used in 2 crates (via ocidir)

MIT/Apache

50KB
936 lines

RFC 8785 Canonical JSON serialization for Rust

docs.rs Crates.io

This crate provides a serde_json::Formatter to serialize data in canonical JSON form as defined by RFC 8785.

use canon_json::CanonicalFormatter;
use serde::Serialize;
use serde_json::json;
let value = json!({"b": 12, "a": "qwerty"});
let mut buf = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(&mut buf, CanonicalFormatter::new());
value.serialize(&mut ser).unwrap();
assert_eq!(buf, br#"{"a":"qwerty","b":12}"#);

History

This repository was originally forked from https://github.com/engineerd/cjson as it is unmaintained. But it ended up being redesigned to use the "formatter" approach that is used by olpc-cjson.

Dependencies

~0.7–1.6MB
~34K SLoC