#json

bin+lib olpc-cjson

serde_json Formatter to serialize as OLPC-style canonical JSON

4 releases

0.1.3 Mar 3, 2023
0.1.2 Oct 3, 2022
0.1.1 Jul 30, 2021
0.1.0 Nov 9, 2019

#130 in Parser implementations

Download history 5350/week @ 2023-02-05 6046/week @ 2023-02-12 6002/week @ 2023-02-19 8001/week @ 2023-02-26 9894/week @ 2023-03-05 8738/week @ 2023-03-12 7446/week @ 2023-03-19 7505/week @ 2023-03-26 4711/week @ 2023-04-02 6051/week @ 2023-04-09 6160/week @ 2023-04-16 4530/week @ 2023-04-23 5304/week @ 2023-04-30 5031/week @ 2023-05-07 5542/week @ 2023-05-14 5491/week @ 2023-05-21

21,502 downloads per month
Used in 32 crates (5 directly)

MIT/Apache

22KB
379 lines

olpc-cjson provides a serde_json::Formatter to serialize data as canonical JSON, as defined by OLPC and used in TUF. It is developed as part of tough, a Rust library for using TUF repositories.

OLPC's canonical JSON specification is subtly different from other "canonical JSON" specifications, and is also not a strict subset of JSON (specifically, ASCII control characters 0x00–0x1f are printed literally, which is not valid JSON). Therefore, serde_json cannot necessarily deserialize JSON produced by this formatter.

This crate is not developed or endorsed by OLPC; use of the term is solely to distinguish this specification of canonical JSON from other specifications of canonical JSON.

use olpc_cjson::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}"#);

Dependencies

~1–1.5MB
~55K SLoC