Skip to main content

Lightweight pure-Python JSON ↔ CBOR encoder/decoder with optional zlib compression

Project description

Cbor-J

Lightweight pure-Python library to encode/decode JSON strings to/from CBOR — with optional zlib compression.

Perfect for reducing storage size of large JSON files.

Features

  • Pure Python, no dependencies
  • Simple API: encode(json_str, compress=False) → bytes, decode(bytes, compress=False) → str
  • Optional zlib compression (like EU Digital COVID Certificate format, without signing/Base45)
  • Includes CLI tool

Installation

pip install cborJ

Usage

import json

from cborJ import decode, encode

json_data = {
        "name": "Alice",
        "age": 30,
        "email": "alice@example.com",
        "isMember": True,
        "favorites": {
            "color": "blue",
            "food": "pizza"
        },
        "shoppingList": ["eggs", "milk", "bread"]
    }
json_str = json.dumps(json_data)


print("--------------Encoding--------------")

# Encode → (no compression)
encoded = encode(json_str, compress=False)
print(f"Original: {json_str.encode()}\n")
print(f"CBOR:     {encoded}\n")

# Encode → (with compression)
encoded_zip = encode(json_str, compress=True)
print(f"Original: {json_str.encode()}\n")
print(f"CBOR:     {encoded_zip}\n")

print("--------------Decoding--------------")

# Decode → (with compression)
decoded_zip = decode(encoded_zip, compress=True)
print(f"CBOR:     {encoded_zip}\n")
print(f"Original: {decoded_zip.encode()}\n")

CLI Tool

Encode JSON file to CBOR (stdout)

cborJ encode data.json > data.cbor

Decode back

cborJ decode data.cbor > data.json

With compression

cborJ encode --compress big.json > big.cbor

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

cborj-0.1.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cborj-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file cborj-0.1.1.tar.gz.

File metadata

  • Download URL: cborj-0.1.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cborj-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9714bc70c8845d341bac789790329c611cc81932e2a584c748b627172812f4fb
MD5 64c59ca6d78915c5db20666f11fff38a
BLAKE2b-256 7e52e54c9a820a0a1568a604d97a7be2ec398e15344ff0ef6be8e9794d75fa39

See more details on using hashes here.

File details

Details for the file cborj-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cborj-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for cborj-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bfbedf33c1ceb37539469d4d38abea30d786a77061232f77887cf371514ad37
MD5 e30eac4eb582ec9e3209495e2169e147
BLAKE2b-256 976a5f9440fd4f91bfcb1cb27d8014049a8bfc090a02e3006b13807ae814b580

See more details on using hashes here.

Supported by

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