Skip to main content

jsonweir

Incremental JSON parsing for code that receives JSON in chunks.

jsonweir consumes text incrementally and emits parse events as soon as they are available. It is useful for streaming model responses, network payloads, or other producers where you want to react before the full JSON document has been received.

What it does

  • Parses JSON from one or more string chunks.
  • Emits structural events for objects and arrays.
  • Emits scalar events for numbers, booleans, and null.
  • Emits string values incrementally with StringDelta events.
  • Tracks a path for every event using object keys and array indexes.
  • Reports parse failures as JsonParseError events instead of raising for normal parse errors.

Installation

pip install jsonweir

Basic usage

Import the parser from the package root. Import events from jsonweir.events.

from jsonweir import IncrementalJsonParser
from jsonweir.events import EndString, JsonParseError, StringDelta

parser = IncrementalJsonParser()

chunks = [
    '{"message": "hel',
    'lo", "count": 2}',
]

for chunk in chunks:
    for event in parser.feed(chunk):
        if isinstance(event, StringDelta):
            print("string chunk:", event.path, event.text)
        elif isinstance(event, EndString):
            print("string value:", event.path, event.value)
        elif isinstance(event, JsonParseError):
            raise ValueError(event.message)

for event in parser.finish():
    if isinstance(event, JsonParseError):
        raise ValueError(event.message)

Events

Every event has a path except JsonParseError. Paths are tuples containing object keys and array indexes.

For this JSON:

{"items": [{"name": "book"}]}

the string "book" is reported at:

("items", 0, "name")

The event classes are:

  • StartObject
  • EndObject
  • StartArray
  • EndArray
  • Key
  • StartString
  • StringDelta
  • EndString
  • Scalar
  • JsonParseError

String streaming

Strings are split into StartString, zero or more StringDelta events, and EndString. Deltas are emitted at chunk boundaries and before escape sequences are decoded.

from jsonweir import IncrementalJsonParser
from jsonweir.events import StringDelta

parser = IncrementalJsonParser()

events = []
events.extend(parser.feed('["hel'))
events.extend(parser.feed('lo"]'))
events.extend(parser.finish())

assert StringDelta(path=(0,), text="hel") in events
assert StringDelta(path=(0,), text="lo") in events

Object keys are reported with Key events. They do not emit string delta events.

Errors

Invalid input produces JsonParseError(message, fatal=True) events. After a fatal error, callers should stop feeding input and discard the parser instance.

from jsonweir import IncrementalJsonParser
from jsonweir.events import JsonParseError

parser = IncrementalJsonParser()
events = list(parser.feed("[1,]")) + list(parser.finish())

errors = [event for event in events if isinstance(event, JsonParseError)]
assert errors

Development

Run the package tests:

uv sync
uv run pytest

Metadata

Release files for jsonweir 0.1.0

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

Source distribution (sdist)

Source distribution for jsonweir 0.1.0
File Size Uploaded Provenance Actions
jsonweir-0.1.0.tar.gz 30.0 kB With provenance Details for jsonweir-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jsonweir 0.1.0
File Interpreter ABI Platform Actions
jsonweir-0.1.0-py3-none-any.whl Python 3 none any Details for jsonweir-0.1.0-py3-none-any.whl

Total release size: 39.1 kB

Release files / jsonweir-0.1.0.tar.gz

Download URL jsonweir-0.1.0.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0823551700b06bf4b1605d52d3514e6581c6c5f72d0295ce8b47eb024e6420b2
BLAKE2b-256 checksum
How to use checksums
0e59140db46bc2f05dbc9fd09169b1aab52ffd9b9a8e24144bf295096c0e3d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

Release files / jsonweir-0.1.0-py3-none-any.whl

Download URL jsonweir-0.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b2615c89f34dd9878a23b826128746498536bdff05e389fb1056d3f8159ea5a
BLAKE2b-256 checksum
How to use checksums
60836043193396a9fc6dc9e6cf01cd5d85a329631c9b27969b75e112060022e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

Security for jsonweir 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jsonweir-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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