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 в†’ JSONL

json_to_jsonl("data.json", "data.jsonl")

Note: data.json must contain a top-level list ([{}, {}, ...]).

JSONL в†’ 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.0.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.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonl_tools-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 6182006f1e0c0569ca5974042034787ff9b60346d07883e92511b75591742360
MD5 6b650c531babfc87bf8a44e47a9a4d67
BLAKE2b-256 5371489743a5b102cd98413b9ad0394998c46f8f4f26cec56c7ccdc228cb0926

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonl_tools-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9553a0823e753bdb44fe67ded84e7d09fd2eff6b1594d76c8e8a5b51b9dc9fcd
MD5 eb6540898bf1632b77afd17bf241e3f3
BLAKE2b-256 46408554d1b6feda2a154b85d4e7d3de6e01f67b69c27f4b90b6a8e212c6c1f0

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