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

Uploaded Source

Built Distribution

canonicaljson-1.6.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicaljson-1.6.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for canonicaljson-1.6.1.tar.gz
Algorithm Hash digest
SHA256 a93664f698556dbd4bab9c3fc4fb35834cf2535da1ea00b6b7758d8fe2bbb824
MD5 7ae9f463b863eb6e952116e71d9eed3c
BLAKE2b-256 a49f56a4acefb9c93eae6fcad88d42f35f11b7c02547f99f83c97a5eed7914f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canonicaljson-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ccf1079a928b520b9b7dd8567f842ca44d1877d8b6540b83254b8a6ac6cfc11
MD5 fe39a73584ed70916694a48c39feff01
BLAKE2b-256 908feb4abcfe092269e29a0b4142ed38eec8e610510c5e649235038e50c6cf1d

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