Skip to main content

Canonical JSON

Project description

Latest Version https://img.shields.io/travis/matrix-org/python-canonicaljson.svg

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicaljson-1.4.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7

File hashes

Hashes for canonicaljson-1.4.0.tar.gz
Algorithm Hash digest
SHA256 899b7604f5a6a8a92109115d9250142cdf0b1dfdcb62cdb21d8fb5bf37780631
MD5 e7c017175bc21e3801fd807f9ed9546e
BLAKE2b-256 f524a18b5a8cec3c90bd85d8428493268034c8be81939d99c065c62a1f78f999

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicaljson-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.7

File hashes

Hashes for canonicaljson-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1582cb736a020e5ca4e700185db89037fbcd91d54623c0c5d830724df6803ae
MD5 29d764fb5e41ef8ff9045fe1fbec9898
BLAKE2b-256 769e945399eef906b4698404d080d14d130ed758507ca5744195967c1a5cdc87

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