jsonl
Zero-dependency Python library for reading, writing, and compressing JSON Lines files.
Documentation · Changelog · PyPI
import jsonl
jsonl.dump([{"name": "Alice"}, {"name": "Bob"}], "file.jsonl.gz")
for item in jsonl.load("file.jsonl.gz"):
print(item)
If you know json.dump and json.load, you already know jsonl.
Install
pip install py-jsonl
Python 3.8+ · No dependencies · Single file
Features
- Familiar API — similar
dump/loadinterface as Python'sjsonmodule. - Streaming by default — iterators in, iterators out. Constant memory.
- Automatic compression —
.gz,.bz2,.xz,.zst(Python ≥ 3.14). Detected by extension or magic bytes. - Archive support — read/write
.zip,.tar.gz,.tar.bz2,.tar.xznatively. - URL loading — pass a URL to
load()orload_archive()directly. - Pluggable serialization — swap in
orjson,ujson, or any encoder/decoder viacls. - Error tolerance — skip malformed lines instead of crashing.
- Command-line interface — a
json-stylejsonlcommand for shell pipelines. - Sequential splitting — divide a stream into fixed-size JSONL files.
- Zero dependencies — pure standard library; single
.pyfile you can vendor.
Fully compliant with jsonlines.org and ndjson specs.
API
Reading
| Function | Description |
|---|---|
jsonl.load(source, **kw) |
File, URL, or file-like → lazy iterator |
jsonl.open_stream(source, **kw) |
File, URL, or binary file-like → decompressed stream |
jsonl.loads(text, **kw) |
JSON Lines string → lazy iterator |
jsonl.load_archive(file, **kw) |
Unpack JSONL files from ZIP/TAR |
jsonl.loader(stream, broken, **kw) |
Low-level line-stream deserializer |
Writing
| Function | Description |
|---|---|
jsonl.dump(iterable, file, **kw) |
Write to file (any format) |
jsonl.dumps(iterable, **kw) |
Serialize to string |
jsonl.dump_fork(paths, **kw) |
Write to multiple files at once |
jsonl.dump_archive(path, data, **kw) |
Pack into ZIP/TAR archive |
jsonl.dumper(iterable, **kw) |
Low-level generator → formatted lines |
All functions accept
clsand**kwargsfor custom encoding/decoding.
Examples
Archives (ZIP / TAR)
import jsonl
data = [
("users.jsonl", [{"name": "Alice"}, {"name": "Bob"}]),
("orders.jsonl", [{"id": 1, "total": 99.90}]),
]
jsonl.dump_archive("data.tar.gz", data)
for filename, items in jsonl.load_archive("data.tar.gz"):
for item in items:
print(filename, item)
Custom serializer (orjson)
import orjson
import jsonl
data = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
jsonl.dump(data, "fast.jsonl", text_mode=False, cls=orjson.dumps)
for item in jsonl.load("fast.jsonl", cls=orjson.loads):
print(item)
Multiple output files
import jsonl
data = [
("a.jsonl", [{"x": 1}]),
("b.jsonl", [{"x": 2}]),
("a.jsonl", [{"x": 3}]), # appends to a.jsonl
]
jsonl.dump_fork(data)
Custom encoder/decoder classes
import datetime
import json
import jsonl
class DateEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.date):
return obj.isoformat()
return super().default(obj)
data = [{"event": "launch", "date": datetime.date(2026, 1, 15)}]
jsonl.dump(data, "events.jsonl", cls=DateEncoder)
Command-line interface
Installing the package also provides the jsonl command (equivalently python -m jsonl):
jsonl [OPTIONS] [INFILE] [OUTFILE]
INFILE may be a JSON Lines file, a ZIP/TAR archive, a URL, or - for stdin. When OUTFILE is omitted, output is
written to stdout. Processing is streamed and compression is detected automatically.
# Validate and stream a file
jsonl input.jsonl
# Shell pipelines
cat input.jsonl | jsonl --compact > output.jsonl
# Convert compression formats
jsonl input.jsonl.gz output.jsonl.xz
# Read every recognized JSONL/NDJSON member from a ZIP/TAR archive
jsonl dataset.zip merged.jsonl
# Select archive members
jsonl --member '2026/*.jsonl' dataset.tar.gz output.jsonl
# Skip invalid records (returns 1 if any are found)
jsonl --broken input.jsonl output.jsonl
# Split into files of 50,000 records; output compression follows the output suffix
jsonl --split 50000 input.jsonl part.jsonl.gz
Useful options include --compact, --sort-keys, --ascii, --member, --broken, and --split. File output is
atomic unless --split is used: split files are written incrementally, so files completed before an error remain.
Full command-line documentation
Supported Formats
| Type | Extensions |
|---|---|
| Plain | .jsonl |
| Compressed | .jsonl.gz · .jsonl.bz2 · .jsonl.xz · .jsonl.zst¹ |
| ZIP | .zip |
| TAR | .tar · .tar.gz · .tar.bz2 · .tar.xz · .tar.zst¹ |
¹ Requires Python ≥ 3.14
Contributing
See CONTRIBUTING.md for setup, testing, and PR guidelines.
License
Metadata
Release files for py-jsonl 1.5.4
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 |
|---|---|---|---|---|
| py_jsonl-1.5.4.tar.gz | 35.2 kB | Without provenance | Details for py_jsonl-1.5.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_jsonl-1.5.4-py3-none-any.whl | Python 3 | none | any | Details for py_jsonl-1.5.4-py3-none-any.whl |
Total release size: 53.2 kB
Release files / py_jsonl-1.5.4.tar.gz
| Download URL | py_jsonl-1.5.4.tar.gz |
|---|---|
| Size | 35.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73be5760244e990b5cc78a98068d1d8bf6376db48c3851ef8bedf86bd5e41350
|
|
BLAKE2b-256 checksum How to use checksums |
fda6a52bad6badc40201f22f3315f64d4ee6867bd6e656ad1c24631ab257e825
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / py_jsonl-1.5.4-py3-none-any.whl
| Download URL | py_jsonl-1.5.4-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d60f79a73f5fc581dc4547f0cd0f04c20a402e64a88fe252b354933e0839fc3c
|
|
BLAKE2b-256 checksum How to use checksums |
7e0dc7781b1a9448092480cdd538b3cdb57f71589076ade4ad03e6e43f67a122
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for py-jsonl 1.5.4
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.