jsonseq is a Python library that provides support for encoding and decoding JSON text sequences as defined by RFC 7464. This format is designed for streaming multiple JSON objects, each prefixed by an ASCII Record Separator (0x1E) and terminated by a Line Feed (0x0A). It's particularly useful for handling large or indefinite streams of JSON data incrementally. The current version is 1.0.0, with releases historically following an as-needed cadence.
pip install jsonseqVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode a list of Python dictionaries into a JSON text sequence using `JSONSeqEncoder` and then decode it back into Python objects using `JSONSeqDecoder`. It uses `io.BytesIO` to simulate file or network streams.
Be aware of this leniency when interoperating with other systems. If strict adherence to the initial RS is required for output, manually prepend `b'\x1e'` to the stream or first record if the library's default behavior doesn't include it. For decoding, be aware that sequences starting without an RS will still be processed.
Wrap the iteration over the `JSONSeqDecoder` in a `try...except json.JSONDecodeError` block to catch and handle individual malformed JSON records gracefully. This allows your application to log errors and continue processing subsequent valid records in the stream.
Ensure that the underlying stream (e.g., `io.TextIOWrapper` or a network socket) is opened or configured with `encoding='utf-8'`. When working with raw bytes streams, ensure any manual decoding operations (e.g., `bytes.decode()`) also specify `utf-8`.
Ensure all JSON objects passed to `JSONSeqEncoder` are valid, or, when decoding, wrap the iteration over `JSONSeqDecoder` in a `try...except json.JSONDecodeError` block to catch and handle malformed records gracefully. Log the error details (line, column, char) to pinpoint the problematic data.
Verify the actual encoding of the source data. If it's not UTF-8 (e.g., Latin-1, Windows-1252), you'll need to decode the raw bytes stream with the correct encoding *before* passing it to `JSONSeqDecoder` or ensure the file/network stream is opened with the appropriate `encoding` parameter.
This typically indicates an incomplete JSON object or a truncated stream. Ensure the entire JSON text sequence is available to the decoder. If reading from a file, verify the file is not truncated. When processing network streams, handle `EOFError` or ensure all expected data chunks are received.
No dependency data recorded yet.