Registry / serialization / streamingjson

streamingjson

JSON →
library0.0.5pypiunverified

StreamingJSON is a Python library designed to preprocess incomplete JSON strings, transforming them into valid, parseable JSON in real-time. This addresses challenges in stream JSON parsing, especially relevant for Large Language Models (LLMs), by enabling immediate data processing without waiting for full JSON generation. It works by completing fragmented JSON, allowing other standard JSON libraries to parse its output seamlessly. The library is currently in an active development phase, with version 0.0.5 being the latest release, and follows a rapid release cadence.

pip install streamingjson
INSTALL
IMPORT
SIG · STREAMINGJSON
S
streamingjson
serializationenv0.0.5
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Lexer
from streamingjson import Lexer

This example demonstrates how to initialize the `Lexer`, append string segments incrementally, and retrieve the completed (syntactically valid) JSON at any point in the stream. It highlights the use of a new `Lexer` instance per stream and the library's ability to handle various JSON fragments and escaped characters.

import streamingjson # NOTE: A new Lexer instance is required for each JSON stream. lexer = streamingjson.Lexer() # Append initial JSON segment lexer.append_string('{"a":') print(lexer.complete_json()) # Expected: {"a":null} # Append more JSON segments lexer.append_string('[tr') print(lexer.complete_json()) # Expected: {"a":[true]} lexer.append_string('ue], "b": "hello') print(lexer.complete_json()) # Expected: {"a":[true], "b": "hello"} # Example with escaped characters new_lexer = streamingjson.Lexer() new_lexer.append_string('{"key": "value with \"quote\" and \\slash"') print(new_lexer.complete_json()) # Expected: {"key": "value with \"quote\" and \\slash"}
Debug
Known issues
gotchaEach new JSON stream requires a fresh `streamingjson.Lexer()` instance. Reusing a `Lexer` instance for a different stream without re-initialization can lead to incorrect parsing results or unexpected behavior.
fix
Always instantiate `streamingjson.Lexer()` for each new independent JSON stream you intend to process.
affects: All versions
gotchaStreamingJSON acts as a *preprocessor* to complete incomplete JSON strings into syntactically valid JSON. It does not directly provide an object-streaming interface (like `ijson` or `json-stream`) that yields Python objects as they are parsed from a raw stream. Users must use a standard JSON library (e.g., Python's `json` module) on the *output* of `complete_json()` to convert it into Python objects.
fix
Understand that `Lexer.complete_json()` provides a *string* representation of valid JSON. Use `json.loads(lexer.complete_json())` for object deserialization.
affects: All versions
breakingThe library is in an early development stage (0.0.x series). APIs, internal structures, and behavior may change significantly in future minor or patch releases, potentially introducing breaking changes without major version bumps.
fix
Pin your dependency to an exact version (e.g., `streamingjson==0.0.5`) in `requirements.txt` to avoid unexpected breakage from updates. Review changelogs carefully when upgrading.
affects: <1.0.0
gotchaA bug in earlier versions (fixed in 0.0.5) caused parsing errors when a JSON string contained a literal slash character (`/`). While fixed, this highlights the potential for subtle parsing edge cases in handling string content, especially with complex escape sequences or Unicode.
fix
Ensure you are using `streamingjson` version `0.0.5` or later to benefit from critical bug fixes related to string parsing. Report any unexpected parsing behavior for complex string content.
affects: <0.0.5
Upgrade
Version history
0.0.5latest on PyPI · released Sep 20, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources

No resource links recorded.

streamingjson — pip install streamingjson · libregistry