A lightweight, dependency-free Python library for JSON Array - read, write, compress incrementally with ease
Project description
jsoneasy
A lightweight, dependency-free Python library for JSON Array — read, write, compress incrementally with ease
Documentation · Changelog · Issues
jsoneasy provides a simple, Pythonic API for working with JSON Arrays in a memory-efficient way.
It follows the conventions of Python's standard json module — if you know json.dump and json.load,
you already know how to use jsoneasy.
Fully compliant with the json specifications.
Features
| Feature | Description |
|---|---|
| 🌎 Familiar API | Interface similar to the standard json module (dump, load) |
| ⚡ Streaming by default | Read and write incrementally via iterators, keeping memory usage low |
| 🗜️ Built-in compression | Transparent support for gzip, bzip2, and xz |
| 📦 Archive support | Read and write ZIP and TAR archives (.tar.gz, .tar.bz2, .tar.xz) |
| 📥 Load from URLs | Pass a URL directly to load() or load_archive() |
| 🚀 Customizable serialization | Extend via standard JSONEncoder/JSONDecoder subclasses and extra kwargs |
| 🐍 Zero dependencies | Uses only the Python standard library — nothing else |
Installation
pip install py-jsoneasy
Requires Python 3.8+. No external dependencies.
Quick Start
Write
import jsoneasy
data = [
{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]},
{"name": "May", "wins": []},
]
jsoneasy.dump(data, "players.json")
Read
import jsoneasy
for item in jsoneasy.load("players.json"):
print(item)
Read from a URL
import jsoneasy
for item in jsoneasy.load("https://restcountries.com/v3.1/all?fields=name,capital"):
print(item)
Compressed files
The compression format is determined automatically — by file extension when writing, and by magic numbers when reading if the file extension is not recognized:
import jsoneasy
data = [{"key": "value"}]
jsoneasy.dump(data, "file.json.gz") # gzip
jsoneasy.dump(data, "file.json.bz2") # bzip2
jsoneasy.dump(data, "file.json.xz") # xz
for item in jsoneasy.load("file.json.gz"):
print(item)
Archives (ZIP / TAR)
import jsoneasy
# Write multiple files into an archive
data = [
("users.json", [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]),
("orders.json", [{"id": 1, "total": 99.90}, {"id": 2, "total": 45.00}]),
]
jsoneasy.dump_archive("data.zip", data)
# Read them back from the archive
for filename, items in jsoneasy.load_archive("data.zip", pattern="*.json"):
print(f"--- {filename} ---")
for item in items:
print(item)
Multiple output files
import jsoneasy
data = [
("file1.json", [{"name": "Alice"}, {"name": "Bob"}]),
("file2.json", [{"name": "Charlie"}]),
("file1.json", [{"name": "Eve"}]), # appended to file1.json
]
jsoneasy.dump_fork(data)
API Overview
Reading
| Function | Description |
|---|---|
jsoneasy.load(source, **kw) |
Read from a file, URL, or file-like object |
jsoneasy.load_archive(file, **kw) |
Unpack JSON files from a ZIP or TAR archive |
[!TIP] All read functions accept
clsand**kwargsfor custom deserialization (forwarded tojson.JSONDecoder).
Writing
| Function | Description |
|---|---|
jsoneasy.dump(iterable, file, **kw) |
Write objects to a JSON file |
jsoneasy.dump_fork(paths, **kw) |
Write to multiple JSON files at once |
jsoneasy.dump_archive(path, data, **kw) |
Pack multiple JSON files into a ZIP or TAR archive |
[!TIP] All write functions accept
clsand**kwargsfor custom serialization (forwarded tojson.JSONEncoder).
For complete parameter documentation, see the full docs →
Custom Serialization
Extra keyword arguments are forwarded to the underlying json.JSONEncoder / json.JSONDecoder.
You can also pass a custom cls subclass for full control:
import jsoneasy
data = [{"name": "Alice", "score": 9.5}, {"name": "Bob", "score": 7.2}]
jsoneasy.dump(data, "compact.json", separators=(",", ":")) # compact output
jsoneasy.dump(data, "sorted.json", sort_keys=True) # deterministic keys
jsoneasy.dump(data, "pretty.json", indent=2) # indented output
Supported Formats
| Type | Extensions |
|---|---|
| Plain | .json |
| Compressed | .json.gz, .json.bz2, .json.xz |
| ZIP archive | .zip |
| TAR archive | .tar, .tar.gz, .tar.bz2, .tar.xz |
When reading, if the file extension is not recognized, jsoneasy falls back to magic-number detection to identify the compression format automatically.
Contributing
# Install dev dependencies
pip install --group=test --upgrade
# Run tests
python -m pytest tests/
python -m pytest tests/ --cov # run with coverage reporting
# Lint
pip install --group=lint --upgrade
ruff check .
# Docs
pip install --group=doc --upgrade
# zensical usage: https://zensical.org/docs/usage/
zensical build
zensical serve
License
MIT — see LICENSE for details.
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
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 py_jsoneasy-0.0.5.tar.gz.
File metadata
- Download URL: py_jsoneasy-0.0.5.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8212dbf38eaa77043a57cfe7970b6792ec76e485afba327f94eb1b3cc3691dca
|
|
| MD5 |
442e975dfba742f4d78054813888f9fe
|
|
| BLAKE2b-256 |
0cf8c631c91044a4a40f7695dee22edba51b297d3fbc10af7895f229dab7c113
|
File details
Details for the file py_jsoneasy-0.0.5-py3-none-any.whl.
File metadata
- Download URL: py_jsoneasy-0.0.5-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11fdb0b32b0d93a7e54ffd105ad66b5e6b9a2b9a1ccb6c5ab1ac5fb46a44e25c
|
|
| MD5 |
72f66baa9c37efd54f077a9e4e98ecfb
|
|
| BLAKE2b-256 |
034d88657c40c2254ebaf99a191997ce6c40e2b0b2f28fa1c56bdf965a5e6ff4
|