Skip to main content

Canonical JSON

Project description

Latest Version

Features

  • Encodes objects and arrays as RFC 7159 JSON.

  • Sorts object keys so that you get the same result each time.

  • Has no insignificant whitespace to make the output as small as possible.

  • Escapes only the characters that must be escaped, U+0000 to U+0019 / U+0022 / U+0056, to keep the output as small as possible.

  • Uses the shortest escape sequence for each escaped character.

  • Encodes the JSON as UTF-8.

  • Can encode frozendict immutable dictionaries.

Supports Python versions 3.7 and newer.

Installing

pip install canonicaljson

Using

To encode an object into the canonicaljson:

import canonicaljson
assert canonicaljson.encode_canonical_json({}) == b'{}'

There’s also an iterator version:

import canonicaljson
assert b''.join(canonicaljson.iterencode_canonical_json({})) == b'{}'

The underlying JSON implementation can be chosen with the following:

import json
import canonicaljson
canonicaljson.set_json_library(json)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canonicaljson-1.6.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

canonicaljson-1.6.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file canonicaljson-1.6.5.tar.gz.

File metadata

  • Download URL: canonicaljson-1.6.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for canonicaljson-1.6.5.tar.gz
Algorithm Hash digest
SHA256 68dfc157b011e07d94bf74b5d4ccc01958584ed942d9dfd5fdd706609e81cd4b
MD5 73929b035731a23252053e260255db8e
BLAKE2b-256 6413017c9bed81f7f5b72470fe5892b25cc212299bd3d79e2d30f2f99c22c517

See more details on using hashes here.

File details

Details for the file canonicaljson-1.6.5-py3-none-any.whl.

File metadata

File hashes

Hashes for canonicaljson-1.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 806ea6f2cbb7405d20259e1c36dd1214ba5c242fa9165f5bd0bf2081f82c23fb
MD5 8609bc6c32581c9506c1b88d80d0610d
BLAKE2b-256 5aafc8ea2fdea918fed2f85928ab5f1a20111015f807f5038b6bea16c6dacd8a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page