--- id: canonicaljson version: "2.0.0" license: Apache License, Version 2.0 license_treatment: permissive maintenance: active --- # canonicaljson — Canonical JSON License: permissive · Maintenance: active · Downloads: 272.6K/mo ## What it is and what it does Canonicaljson produces deterministic JSON output by enforcing a canonical form: object keys are always sorted, whitespace is eliminated, and character escaping follows RFC 7159 with minimal sequences. This makes the encoded output identical every time for the same input, which is essential for cryptographic signing, content hashing, and any system where reproducible serialization matters. The package wraps either simplejson (by default on CPython) or the standard library json module (on PyPy) and adds a preserialisation hook system to handle custom types. It requires Python 3.7 or newer and has no external runtime dependencies, making it lightweight to integrate into existing projects. Use it for: - Signing JSON data cryptographically: canonical form ensures signatures remain valid across different serialization libraries. - Deduplicating or caching JSON objects: identical input always produces identical bytes, enabling content-addressed storage. - Blockchain or ledger applications: deterministic encoding is critical for consensus and transaction verification. - API request/response logging: canonical form makes log entries comparable and reduces storage by eliminating whitespace. - Testing JSON-producing code: canonical output makes assertions on serialized data deterministic and independent of key order. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Encodes Python objects to canonical JSON with sorted keys, minimal whitespace, and consistent escaping, ensuring identical output for the same input across runs. Yes. Canonicaljson solves a real problem—deterministic JSON serialization—that the standard library does not address. It has no dependencies, low install friction, active maintenance, a permissive license, and no known vulnerabilities. Install it if your application requires reproducible JSON encoding for signing, hashing, or comparison; skip it if you only need standard JSON serialization. ## Install pip install canonicaljson uv add canonicaljson poetry add canonicaljson ## Installing canonicaljson Before you install: Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-05-06 with production-stable status since its 2015 release. License in practice: Apache License 2.0 (permissive) places no significant restrictions on use, modification, or distribution in proprietary or open-source projects. Quickstart: pip install canonicaljson import canonicaljson result = canonicaljson.encode_canonical_json({"key": "value"}) print(result) # b'{"key":"value"}' Requires Python 3.7 or newer. Verify before relying: - Performance characteristics compared to standard library json for large objects. - Whether the preserialisation callback mechanism covers all custom type use cases in practice. ## Package facts - License: Apache License, Version 2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 272.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags canonical json encoding, deterministic json serialization, sorted keys json, minimal whitespace json, rfc 7159 json encoder, consistent json output, json canonicalization, json-serialization, cryptography-adjacent, deterministic-output [View on SkillFed](https://skillfed.io/packages/canonicaljson) · [View on PyPI](https://pypi.org/project/canonicaljson/)