Expand description
§vr-jcs
RFC 8785 JSON Canonicalization Scheme (JCS) for Rust.
Produces canonical JSON suitable for deterministic digest computation, content hashing, and stable serialization boundaries. Implements the RFC 8785 rules that materially affect wire compatibility:
- UTF-16 code-unit sorting for object property names
- ECMAScript-compatible primitive serialization
- UTF-8 output without insignificant whitespace
- duplicate-property rejection on raw JSON parse paths
- I-JSON string / number validation
§API
to_canon_bytes— Serialize anySerializetype to canonical JSON bytesto_canon_string— Serialize anySerializetype to a canonical JSON stringto_canon_bytes_from_slice— Parse raw JSON and return canonical bytes (rejects duplicates)to_canon_string_from_str— Parse raw JSON string and return canonical stringcanonicalize— Sort object keys recursively in aserde_json::Value(in-place)
§Usage
use vr_jcs::to_canon_string;
use serde::Serialize;
#[derive(Serialize)]
struct Receipt {
z_field: u64,
a_field: u64,
}
let receipt = Receipt { z_field: 1, a_field: 2 };
let json = to_canon_string(&receipt).expect("serialization");
assert_eq!(json, r#"{"a_field":2,"z_field":1}"#);Enums§
- JcsError
- Error type for canonical JSON operations.
Functions§
- canonicalize
- Recursively sort all object keys in a JSON value for canonical representation.
- to_
canon_ bytes - Serialize any
Serializetype to canonical JSON bytes. - to_
canon_ bytes_ from_ slice - Parse raw JSON text and return canonical JSON bytes.
- to_
canon_ string - Serialize any
Serializetype to a canonical JSON string. - to_
canon_ string_ from_ str - Parse raw JSON text and return a canonical JSON string.