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

Uploaded Source

Built Distribution

canonicaljson-1.6.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicaljson-1.6.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for canonicaljson-1.6.0.tar.gz
Algorithm Hash digest
SHA256 8739d5fd91aca7281d425660ae65af7663808c8177778965f67e90b16a2b2427
MD5 d12fd97e6d0e1064d2c451092024f780
BLAKE2b-256 c0cbd1d996a30d12c7cc488994c7bc89fad1ae27cf88b46621be63daeba5103d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicaljson-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for canonicaljson-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7230c2a2a3db07874f622af84effe41a655e07bf23734830e18a454e65d5b998
MD5 3e5e3c943a475a8dd7706984feda4bd2
BLAKE2b-256 c2ed17d218c6a55117f797c0dd67434838c28101024f22ce6ea96a5737ec3826

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