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.5 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.5.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

canonicaljson-1.5.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicaljson-1.5.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for canonicaljson-1.5.0.tar.gz
Algorithm Hash digest
SHA256 5ebddcd74c5b066ee68ecca56465338e9b1380467e0a906f4797697c9fb381e2
MD5 b7b0129141e41c1c7dd0808132e0a249
BLAKE2b-256 c7eaa00c3324ba00295ae74a25b4df261d67d0fbb10612782c82078aa28a1e5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicaljson-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for canonicaljson-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daaf19a4de75eba7dc7a7110e70b1c9add25e3a7f01081769920b03d1fea3995
MD5 c8cba2e35d881bf2c9bbe932393e5229
BLAKE2b-256 b2d2437a599164fa528b2d5a4bbfe78c7cbab49e4c5ae4c982cd5af3abb7bd24

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