JSON Better
A Python library used to simplify encoding/decoding JSON while handling special
types such as Decimal and datetime.
Please see LICENSE for further information.
See Releases for changes from release to release.
Requires
jsonb requires python 3.10 or higher
Installation
pip install jsonb
Usage
import jsonb
from decimal import Decimal
from datetime import datetime
# Encode special types
s = jsonb.encode({
'amount': Decimal('12.50'),
'when': datetime(2023, 3, 15, 12, 0, 0)
})
# Decode floats as Decimal by default
data = jsonb.decode('{"amount": 12.50}')
# data['amount'] is Decimal('12.5')
# Pass additional arguments through to the json module
s = jsonb.encode(data, indent=2, sort_keys=True)
data = jsonb.decode(s, parse_int=Decimal)
File helpers
import jsonb
# Load / store by path (~ is expanded)
data = jsonb.load('~/config.json')
jsonb.store(data, '~/config.json', indent=2)
# Or work with open file objects
with open('data.json', 'r') as f:
data = jsonb.decodef(f)
with open('data.json', 'w') as f:
jsonb.encodef(data, f, indent=2)
Custom types
import jsonb
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
jsonb.add_class(Point, lambda p: {'x': p.x, 'y': p.y})
print(jsonb.encode(Point(1, 2)))
Metadata
Release files for jsonb 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jsonb-1.0.1.tar.gz | 4.4 kB | Without provenance | Details for jsonb-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jsonb-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for jsonb-1.0.1-py3-none-any.whl |
Total release size: 8.7 kB
Release files / jsonb-1.0.1.tar.gz
| Download URL | jsonb-1.0.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77265ea2310c9909f5465dd7893dfb22370b2bb5f281869946bd1465e4f9b229
|
|
BLAKE2b-256 checksum How to use checksums |
f3c7e05ae22a733c2ac230e09f2fcb1282b6c71c482f108d1f24981dc9fc808f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / jsonb-1.0.1-py3-none-any.whl
| Download URL | jsonb-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38982eff3a8084a7c13c1401d519f1645768d92eedc42e56797b933b8c9f7238
|
|
BLAKE2b-256 checksum How to use checksums |
d8feca12bd5d967e6d7e69b544727c87abb31a41d101554599ff896aad9a4583
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for jsonb 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.