JCS - JSON Canonicalization

0.2.1 · active · verified Sun Apr 12

JCS (JSON Canonicalization Scheme) for Python 3 is a library that provides RFC 8785 compliant JSON canonicalization. It ensures a deterministic representation of JSON data, crucial for cryptographic operations like hashing and signing where data integrity and consistent serialization are paramount. The current version is 0.2.1, released on April 10, 2022. The project appears to have a stable, though not rapid, release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `jcs.canonicalize` to obtain the canonical JSON string from a Python dictionary. The output will be a UTF-8 encoded, sorted, and consistently formatted JSON string according to RFC 8785.

import jcs

data_to_canonicalize = {
    "name": "Alice",
    "age": 30,
    "isStudent": False,
    "courses": ["Math", "Science"],
    "address": {
        "street": "123 Main St",
        "zip": "12345"
    }
}

canonical_json = jcs.canonicalize(data_to_canonicalize)
print(canonical_json)

view raw JSON →