{"id":4584,"library":"jcs","title":"JCS - JSON Canonicalization","description":"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.","status":"active","version":"0.2.1","language":"en","source_language":"en","source_url":"https://github.com/titusz/jcs","tags":["json","canonicalization","rfc8785","deterministic","serialization","hashing"],"install":[{"cmd":"pip install jcs","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary function `canonicalize` is accessed directly via the `jcs` module, not typically imported directly.","wrong":"from jcs import canonicalize","symbol":"canonicalize","correct":"import jcs\ncanonical_json = jcs.canonicalize(data)"}],"quickstart":{"code":"import jcs\n\ndata_to_canonicalize = {\n    \"name\": \"Alice\",\n    \"age\": 30,\n    \"isStudent\": False,\n    \"courses\": [\"Math\", \"Science\"],\n    \"address\": {\n        \"street\": \"123 Main St\",\n        \"zip\": \"12345\"\n    }\n}\n\ncanonical_json = jcs.canonicalize(data_to_canonicalize)\nprint(canonical_json)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure that floating-point values are handled with care, or consider representing monetary or sensitive numeric data as strings if exact cross-platform canonicalization is paramount and floating-point variations are unacceptable.","message":"Floating-point number representation in JCS (RFC 8785) can be subtly different from standard float-to-string conversions in some languages. While `jcs` aims for compliance, users should be aware of potential discrepancies when comparing canonicalized output across different language implementations or with specific test vectors, as precision issues or specific formatting rules (e.g., for `1e+23` vs `1.0e23`) might arise depending on the underlying float implementation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all input data is composed of standard JSON-compatible Python types. Custom objects must be converted to standard types before passing them to `jcs.canonicalize`.","message":"The library expects Python data structures that are directly convertible to JSON (dictionaries, lists, strings, numbers, booleans, and `None`). Passing non-standard Python objects or custom classes that are not implicitly JSON-serializable will result in `TypeError` or unexpected output during canonicalization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be specific in searches, e.g., 'python jcs json canonicalization', and verify the source (`github.com/titusz/jcs` for this library) to avoid using an unrelated package.","message":"This Python 'jcs' library for JSON canonicalization is entirely distinct from the 'jcs' module used within Juniper Junos OS for network device automation scripts. Searching for 'python jcs' might yield results related to the Juniper module, leading to confusion.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For applications requiring high performance with extremely large JSON payloads, benchmark `jcs` against other serialization methods. If performance is critical, consider optimizing input data structures or exploring alternative canonicalization strategies if strictly RFC 8785 compliance can be relaxed.","message":"While not explicitly documented for the Python version, a related Elixir implementation of JCS (based on this Python package) notes that its JSON encoding 'is probably orders of magnitude slower than the Jason library' due to sorting object properties based on UTF-16 encoded keys. This suggests that `jcs` might not be optimized for extreme performance on very large JSON structures.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}