Skip to main content

json-arrays

PyPI version PyPI - Python Version PyPI - Downloads

Maturity badge - level 3 Stage

Code Coverage

CI(check) CI(release) CI(scheduled) CI(test)

Read and write JSON lazy, especially json-arrays.

Handles both the JSON format:

[
  {
    "a": 1
  },
  {
    "a": 2
  }
]

As well as JSON LINES format:

{"a":1}
{"a": 2}

Also supports streaming from gzipped files.

Uses orjson if present, otherwise standard json.

Usage

Installation

# Using standard json
pip install json-arrays

# Using orjson
pip install json-arrays[orjson]

Note

This library prefers files opened in binary mode. Therefore does all dumps-methods return bytes.

All loads methods handles str, bytes and bytesarray arguments.

Examples

Allows you to use json.load and json.dump with both json and json-lines files as well as dumping generators.

import json_arrays

# This command tries to guess format and opens the file
data = json_arrays.load_from_file("data.json") # or data.jsonl

# Write to file, again guessing format
json_arrays.dump_to_file(data, "data.jsonl")
from json_arrays import json_iter, jsonl_iter

# Open and read the file without guessing
data = json_iter.load_from_file("data.json")

# Process file

# Write to file without guessing
jsonl_iter.dump_to_file(data, "data.jsonl")
import json_arrays
def process(data):
    for entry in data:
        # process
        yield entry

def read_process_and_write(filename_in, filename_out):

    json_arrays.dump_to_file(
        process(
            json_arrays.load_from_file(filename_in)
        ),
        filename_out
    )

You can also use json_arrays as a sink, that you can send data to.

import json_arrays

with open("out.json", "bw") as fp:
  # guessing format
  with json_arrays.sink(fp) as sink:
    for data in data_source():
      sink.send(data)

Release Notes

This projects keeps a CHANGELOG.

Development

This project uses pdm. After cloning the repo, just run

make dev
make test

to setup a virtual environment, install dev dependencies and run the unit tests.

Note: If you run the command in a activated virtual environment, that environment is used instead.

Deployment

Push a tag in the format v\d+.\d+.\d+to main-branch, to build & publish package to PyPi.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_arrays-0.15.0.tar.gz (8.2 MB view details)

Uploaded Source

Built Distribution

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

json_arrays-0.15.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file json_arrays-0.15.0.tar.gz.

File metadata

  • Download URL: json_arrays-0.15.0.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for json_arrays-0.15.0.tar.gz
Algorithm Hash digest
SHA256 a30bddc6aff5e8061b06d28ca7a654b1fe6eb127c4077559c0d4df9fc24874b1
MD5 2566359cafb260f33b811605c8e391c0
BLAKE2b-256 cc9df1614c54a07bcc090fbf002a0afeb4ca7305ec6011321396fb485eec83c6

See more details on using hashes here.

File details

Details for the file json_arrays-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: json_arrays-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for json_arrays-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57d0b0ef37562a1b25ccb4356ebe1329193fa9d0d275d319d246d182ebe68d74
MD5 fefccbeefb1cdd88cce5d52543fda362
BLAKE2b-256 c929fabc9205d46361a3a022d718a8d25c1546aa043da417f17e61cb240ca932

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.15.0 This release

2 files

0.14.1

2 files

0.14.0

2 files

Supported by

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