Skip to main content

Incremental JSON Parser

An incremental JSON parser geared towards handling JSON data generated by Large Language Models (LLMs). It is ideal in any situation where you need to process JSON data containing long string values as it arrives in small chunks.

Installation from Git

To install the Incremental JSON Parser, clone the repository and use pip to install the package:

git clone https://github.com/jsh6789/ijp.git
cd ijp
pip install .

Usage

The example below shows how to use the parser in your own scripts:

from ijp import IncrementalJSONParser

json_string = '''
{
    "price": 19.99,
    "itemNo": "3735272",
    "modulars" : [
        {
            "zone": "A",
            "section": 29,
            "position": 10
        },
        {
            "zone": "A",
            "section": 29,
            "position": 15
        }
    ]
}'''

# For demonstratory purpose: break the JSON into chunks.
chunk_size = 4
chunk_list = [
    json_string[i:i + chunk_size] for i in range(0, len(json_string), chunk_size)
]

with IncrementalJSONParser() as parser:
    for chunk in chunk_list:
        parser.send(chunk)
        for token in parser:
            print(token)

This will output:

(['price'], 'float', 19.99)
(['itemNo'], 'stringpart', '37')
(['itemNo'], 'stringpart', '3527')
(['itemNo'], 'stringpart', '2')
(['itemNo'], 'string', '3735272')
(['modulars', 0, 'zone'], 'stringpart', 'A')
(['modulars', 0, 'zone'], 'string', 'A')
(['modulars', 0, 'section'], 'int', 29)
(['modulars', 0, 'position'], 'int', 10)
(['modulars', 1, 'zone'], 'stringpart', 'A')
(['modulars', 1, 'zone'], 'string', 'A')
(['modulars', 1, 'section'], 'int', 29)
(['modulars', 1, 'position'], 'int', 15)

More examples demonstrating uses for this parser can be found in the 'examples' directory.

License

This project is in the public domain. See the accompanying UNLICENSE file for more info.

Metadata

Release files for ijp 1.0.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 ijp 1.0.0
File Size Uploaded
ijp-1.0.0.tar.gz 7.8 kB Details

Built distribution (wheel)

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

Total release size: 13.5 kB

Release files / ijp-1.0.0.tar.gz

Download URL ijp-1.0.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b8aec05c6b77f0a5b7ad5b0f607154c42362a6eeaeb28ee7b59207e42c66fc02
BLAKE2b-256 checksum
How to use checksums
5daea8c04d07efc6f0f652cb39c2e273477ba01a67531bdc93078ec9a7054ccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / ijp-1.0.0-py3-none-any.whl

Download URL ijp-1.0.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02dbfbc17df41b2b4e3aa3c587e3cd1d59c7de2356d5b21bf3713495b02397d7
BLAKE2b-256 checksum
How to use checksums
a9f0464f7b7d5b781c25dad7a162988a90b89535829a0e0f567795b79a896cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.0.0 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