Skip to main content

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 .jsonl files and strings
  • Conversion from .json (list of objects) to .jsonl and 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

jsonl_tools-0.1.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonl_tools-0.1.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file jsonl_tools-0.1.1.tar.gz.

File metadata

  • Download URL: jsonl_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for jsonl_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 677879ee512d7dae1700e2aad6036505667a7ed0554220bbc0a0dc733ee649ee
MD5 215bae9248db4b216a603b362a5373d7
BLAKE2b-256 ded0d6448cd295a8e2f65d4e2dbcbadfed9a4197e55f95f9d9d01620372cc356

See more details on using hashes here.

File details

Details for the file jsonl_tools-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jsonl_tools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for jsonl_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94e7363b7e701941d3cea5126df237bf5a6004a9a2274887fcbb20551b20f449
MD5 270163a91848c037a6bfe4102588f425
BLAKE2b-256 ccddc147e5cc932a15c7bba82dbab180a1f31734bfc97697001de0103b9d4b08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page