json-canon
Serialize JSON into a canonical format.
Safe for generating a consistent cryptographic hash or signature across platforms.
Follows RFC8785: JSON Canonicalization Scheme (JCS)
Features
The JSON Canonicalization Scheme concept in a nutshell:
- Serialization of primitive JSON data types using methods compatible with ECMAScript's
JSON.stringify()
- Lexicographic sorting of JSON
Object
properties in a recursive process - JSON
Array
data is also subject to canonicalization, but element order remains untouched
Serializers
json-canon
JavaScript:
const serialize = require('json-canon')
const json = {
from_account: "543 232 625-3",
to_account: "321 567 636-4",
amount: 500,
currency: "USD"
}
console.log(serialize(json))
// {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
json-canon
Rust:
use json_canon::to_string;
use serde_json::json;
let data = json!({
"from_account": "543 232 625-3",
"to_account": "321 567 636-4",
"amount": 500,
"currency": "USD"
});
println!("{}", to_string(&data)?);
// {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}
Fuzzers
- JavaScript:
json-canon-fuzz