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

from jsonl_tools import loads

s = '{"a": 1}\n{"b": 2}'
data = loads(s)

Write to a JSONL file

from jsonl_tools import dump

data = [{"x": 1}, {"y": 2}]
with open("output.jsonl", "w", encoding="utf-8") as f:
    dump(data, f)

Get a JSONL string

from jsonl_tools import dumps

jsonl_string = dumps([{"a": 1}, {"b": 2}])

Convert Between Formats

JSON $\rightarrow$ JSONL

from jsonl_tools import json_to_jsonl

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

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

JSONL $\rightarrow$ JSON

from jsonl_tools import jsonl_to_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.3.tar.gz (4.3 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.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonl_tools-0.1.3.tar.gz
  • Upload date:
  • Size: 4.3 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.3.tar.gz
Algorithm Hash digest
SHA256 3dab8723bcba51e76c7257483eeed50380fcd5785bd11d97edc073d9818c46e2
MD5 69fadc9ea0316a3f07d55f0516f38d5c
BLAKE2b-256 899bc6a5f58401bdae69d43fdd67b494325b77059ac6306c521240fb23d8b312

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonl_tools-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 469e89322ba797b179fb2d501ee6fb238fc5ffcb4f0e6d9d7674643bed459f0d
MD5 27bf20b42418fcea61cf36d97e2d8fcb
BLAKE2b-256 dba9b29cff6af467bfafec34644ff35552b91c0e647b6e8eb93ba4f3b78463d2

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