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.7.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.7.tar.gz.
File metadata
- Download URL: neatjson-0.10.7.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 |
af297ecc0a6a51979aeec6cd54666e81624a8d82f87d9c1c41dd8ea37b18fdb4
|
|
| MD5 |
8fd8a1144b4ce120cdbe0ee554c7c271
|
|
| BLAKE2b-256 |
c963abbdd379b3a1bbaa819bc069bcb66b5a805534d19e2516b3fe8cdc61ea8f
|
File details
Details for the file neatjson-0.10.7-py3-none-any.whl.
File metadata
- Download URL: neatjson-0.10.7-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 |
a016a7a4513c37343ae985e616a82bfa92d3f5a5aa1123c7cb6e41f8b8251796
|
|
| MD5 |
e03877109f22a986fe9ca8a3cb7f9453
|
|
| BLAKE2b-256 |
216f13dc91138f9200138249e2aaa06cdb0ba26df8db90066f9cdc2c1a81ffd6
|