A Python library for working with JSONL files
Project description
jsonl_tools
jsonl_tools is a minimalist Python library for working with .jsonl (JSON Lines) files. It provides functions similar to Python's built-in json module, along with utilities to convert between .json and .jsonl formats.
What is JSONL?
JSON Lines (JSONL) is a text format where each line is a separate JSON object. This format is commonly used in data processing, logging, and machine learning systems.
Official site: https://jsonlines.org
Features
- Functions that are compatible with
json:load,loads,dump,dumps - Support for reading and writing
.jsonlfiles and strings - Conversion from
.json(list of objects) to.jsonland vice versa - No external dependencies
- Compatible with Python 3.7+
Installation
Install via pip:
pip install jsonl_tools
Alternatively, clone the repository manually:
cd jsonl_tools
Usage
Load JSONL from a file
from jsonl_tools import load
with open("data.jsonl", "r", encoding="utf-8") as f:
data = load(f)
Load JSONL from a string
s = '{"a": 1}\n{"b": 2}'
data = loads(s)
Write to a JSONL file
data = [{"x": 1}, {"y": 2}]
with open("output.jsonl", "w", encoding="utf-8") as f:
dump(data, f)
Get a JSONL string
jsonl_string = dumps([{"a": 1}, {"b": 2}])
Convert Between Formats
JSON $\rightarrow$ JSONL
json_to_jsonl("data.json", "data.jsonl")
Note: data.json must contain a top-level list ([{}, {}, ...]).
JSONL $\rightarrow$ JSON
jsonl_to_json("data.jsonl", "data.json")
This will create a data.json file containing a list of objects.
Project details
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 jsonl_tools-0.1.2.tar.gz.
File metadata
- Download URL: jsonl_tools-0.1.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c108c66387b683cbefe892e7eab652a36e0ef96f39ea274a608994e467aa7726
|
|
| MD5 |
966ca8809a7789c2218b287080f4e04e
|
|
| BLAKE2b-256 |
67ac47b2dbb3c8aeb5fd78470f8a2bf49df82f8f30b6cd40d305e22403f08eee
|
File details
Details for the file jsonl_tools-0.1.2-py3-none-any.whl.
File metadata
- Download URL: jsonl_tools-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
830355ea6b8bbbf0766fab6a86fc584ef6b1de40e1ffecedc46c8fa577a72147
|
|
| MD5 |
a6ba432add6348c019b201f8bdaf0cf8
|
|
| BLAKE2b-256 |
7520cae427bc9f2fdb25bac341e1ff1e41763724bb99cfa1c4a9b663355c6b56
|