Pretty-print your JSON with more power than json.dumps provides.
Project description
NeatJSON for Python
Pretty-print your JSON in Python with more power than json.dumps provides.
See the main project README for full documentation.
Installation
pip install neatjson
Quick Start
from neatjson import neat_json
data = {"b": 42.005, "a": [42, 17], "longer": True, "str": "yes\nplease"}
# Compact output (default)
print(neat_json(data))
# {"b":42.005,"a":[42,17],"longer":true,"str":"yes\nplease"}
# Sorted keys
print(neat_json(data, sort=True))
# {"a":[42,17],"b":42.005,"longer":true,"str":"yes\nplease"}
# Wrapped with indentation
print(neat_json(data, sort=True, wrap=40))
# {
# "a":[42,17],
# "b":42.005,
# "longer":true,
# "str":"yes\nplease"
# }
Python-Specific Features
The following Python types are automatically handled:
- Tuples, sets, and frozensets are serialized as JSON arrays
- Other iterables (
range,deque, generators, etc.) are serialized as arrays - namedtuple instances are serialized as JSON objects (using field names as keys)
- dataclasses are serialized as JSON objects
- Enum values are serialized using their
.value - Decimal and Fraction are serialized as JSON numbers
- Objects with a
__json__()method will have that method called for serialization
Development
cd python
pip install -e ".[dev]"
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
neatjson-0.10.8.tar.gz
(7.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neatjson-0.10.8.tar.gz.
File metadata
- Download URL: neatjson-0.10.8.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11a562f7e3ae303181d28d7704d19cf45e9f97c9fe7bccecb789cad7a2e971d
|
|
| MD5 |
577a2288a56a34f2707943d18e497941
|
|
| BLAKE2b-256 |
83bfc9eb09576c6a9857fb8729d3caf08d89d26a5b24dace4262937fc1473900
|
File details
Details for the file neatjson-0.10.8-py3-none-any.whl.
File metadata
- Download URL: neatjson-0.10.8-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12b0b86c03ab7002c5ce1627605a37ceaaf7e45bff143ae2d06be16941d2e0a4
|
|
| MD5 |
d77a5a81f005b403e3b9ca2f090534fb
|
|
| BLAKE2b-256 |
345544d805de3576c0a0cacedbeb6360b4b58554444db60698bb54d272997a2d
|