Skip to main content

Utilities for working with newline delimited JSON (NDJSON) files, aka JSON Lines.

Latest release 20250528: New dump_ndjson and dumps_ndjson for transcribing obj as NDJSON (includes the trailing newline).

Short summary:

  • append_ndjson: Append an iterable of objects to a file as newline delimited JSON.
  • dump_ndjson: Write obj as a single line of JSON, including the trailing newline.
  • dumps_ndjson: Return obj as a single line of JSON, including the trailing newline.
  • scan_ndjson: Read a newline delimited JSON file, yield instances of dictclass (default dict, otherwise a class which can be instantiated by dictclass(a_dict)).
  • UUIDNDJSONMapping: A subclass of IndexedSetMixin which maintains records from a newline delimited JSON file.
  • write_ndjson: Transcribe an iterable of objects to a file as newline delimited JSON.

Module contents:

  • append_ndjson(f, objs): Append an iterable of objects to a file as newline delimited JSON.

  • dump_ndjson(obj, f): Write obj as a single line of JSON, including the trailing newline.

  • dumps_ndjson(obj): Return obj as a single line of JSON, including the trailing newline.

  • scan_ndjson(f, dictclass=<class 'dict'>, error_list=None): Read a newline delimited JSON file, yield instances of dictclass (default dict, otherwise a class which can be instantiated by dictclass(a_dict)).

    error_list is an optional list to accrue (lineno,exception) tuples for errors encountered during the scan.

  • Class UUIDNDJSONMapping(cs.obj.SingletonMixin, cs.mappings.IndexedSetMixin)``: A subclass of IndexedSetMixin which maintains records from a newline delimited JSON file.

UUIDNDJSONMapping.__init__(self, filename, dictclass=<class 'cs.mappings.UUIDedDict'>, create=False): Initialise the mapping.

Parameters:

  • filename: the file containing the newline delimited JSON data; this need not yet exist
  • dictclass: a optional dict subclass to hold each record, default UUIDedDict
  • create: if true, ensure the file exists by transiently opening it for append if it is missing; default False

UUIDNDJSONMapping.add_backend(self, record): Append record to the backing file.

UUIDNDJSONMapping.rewrite_backend(self): Rewrite the backing file.

Because the record updates are normally written in append mode, a rewrite will be required every so often.

UUIDNDJSONMapping.scan(self): Scan the backing file, yield records.

  • write_ndjson(f, objs): Transcribe an iterable of objects to a file as newline delimited JSON.

Release Log

Release 20250528: New dump_ndjson and dumps_ndjson for transcribing obj as NDJSON (includes the trailing newline).

Release 20211208: Initial PyPI release.

Release files for cs-ndjson 20250528

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-ndjson 20250528
File Size Uploaded
cs_ndjson-20250528.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs-ndjson 20250528
File Interpreter ABI Platform
cs_ndjson-20250528-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 7.4 kB

Release files / cs_ndjson-20250528.tar.gz

Download URL cs_ndjson-20250528.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
351683cab8634c5ffa0b09bc90e2ce405f363d7f9589ac2d17a34782fead007a
BLAKE2b-256 checksum
How to use checksums
19265d2ef26fcff1cd195a969c4bcac1639cba42c827ea91ed52b939ec2d3226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / cs_ndjson-20250528-py2.py3-none-any.whl

Download URL cs_ndjson-20250528-py2.py3-none-any.whl
Size 4.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ab46e55c156b1d89509794212511c8527bd9a2cb8f47d6f8fd26181c8908e01a
BLAKE2b-256 checksum
How to use checksums
56ed4df507cb6a53d1d38a0d520fae7ac1f6be058ba9310bc613d9ebc8a78555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

20250528 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page