Canonical JSON for Rust, compatible with the canonical implementations from Docker and TUF
Go to file
Colin Walters e8557b235b Release 0.2.1
Signed-off-by: Colin Walters <walters@verbum.org>
2025-06-23 07:15:47 -04:00
.github/workflows Fix various clippy lints 2025-06-16 18:55:39 -04:00
src lib: Avoid a panic with unhandled error types 2025-06-23 07:15:47 -04:00
testdata tests: Drop too-precise number from test suite 2025-06-16 18:55:39 -04:00
testdata-cjson-orig Also use test data from cjson 2025-06-16 18:55:39 -04:00
.gitignore Initial commit 2019-10-31 17:07:17 -07:00
Cargo.toml Release 0.2.1 2025-06-23 07:15:47 -04:00
LICENSE-APACHE Import olpc-cjson as of c0d27ad225aba782722bf4d0b586e1714b7eab41 2025-06-16 18:55:39 -04:00
LICENSE-MIT Import olpc-cjson as of c0d27ad225aba782722bf4d0b586e1714b7eab41 2025-06-16 18:55:39 -04:00
README.md Retarget for RFC8785 2025-06-16 18:55:39 -04:00

README.md

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.