utilities for working with newline delimited JSON (NDJSON) files
Project description
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: Writeobjas a single line of JSON, including the trailing newline.dumps_ndjson: Returnobjas a single line of JSON, including the trailing newline.scan_ndjson: Read a newline delimited JSON file, yield instances ofdictclass(defaultdict, otherwise a class which can be instantiated bydictclass(a_dict)).UUIDNDJSONMapping: A subclass ofIndexedSetMixinwhich 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): Writeobjas a single line of JSON, including the trailing newline. -
dumps_ndjson(obj): Returnobjas 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 ofdictclass(defaultdict, otherwise a class which can be instantiated bydictclass(a_dict)).error_listis an optional list to accrue(lineno,exception)tuples for errors encountered during the scan. -
ClassUUIDNDJSONMapping(cs.obj.SingletonMixin, cs.mappings.IndexedSetMixin)``: A subclass ofIndexedSetMixinwhich 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 existdictclass: a optionaldictsubclass to hold each record, defaultUUIDedDictcreate: if true, ensure the file exists by transiently opening it for append if it is missing; defaultFalse
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.
Release Log
Release 20250528: New dump_ndjson and dumps_ndjson for transcribing obj as NDJSON (includes the trailing newline).
Release 20211208: Initial PyPI release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cs_ndjson-20250528.tar.gz.
File metadata
- Download URL: cs_ndjson-20250528.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
351683cab8634c5ffa0b09bc90e2ce405f363d7f9589ac2d17a34782fead007a
|
|
| MD5 |
2d86a22a718f55edd652bcaac927dcca
|
|
| BLAKE2b-256 |
19265d2ef26fcff1cd195a969c4bcac1639cba42c827ea91ed52b939ec2d3226
|
File details
Details for the file cs_ndjson-20250528-py2.py3-none-any.whl.
File metadata
- Download URL: cs_ndjson-20250528-py2.py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab46e55c156b1d89509794212511c8527bd9a2cb8f47d6f8fd26181c8908e01a
|
|
| MD5 |
e253cf8325914f05e701c481293b06d6
|
|
| BLAKE2b-256 |
56ed4df507cb6a53d1d38a0d520fae7ac1f6be058ba9310bc613d9ebc8a78555
|