RFC 8785 (JSON Canonicalization Scheme)

0.1.4 · active · verified Thu Apr 16

rfc8785.py is a pure-Python, no-dependency implementation of RFC 8785, also known as the JSON Canonicalization Scheme (JCS). It provides deterministic serialization of JSON data, essential for cryptographic operations like hashing and signing where byte-identical representations are required for logically equivalent data. The library is actively maintained, with version 0.1.4 being the latest stable release, and it follows an irregular release cadence driven by contributions and fixes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `rfc8785.dumps` to get the canonical byte representation of a Python dictionary. The output is always UTF-8 encoded bytes with keys sorted lexicographically, and specific number and literal serialization as per RFC 8785.

import rfc8785

data = {
    "name": "Alice",
    "age": 30,
    "isStudent": False,
    "courses": ["Math", "Science"],
    "address": {
        "city": "New York",
        "zip": "10001"
    }
}

canonical_bytes = rfc8785.dumps(data)
print(canonical_bytes.decode('utf-8'))

view raw JSON →