Skip to main content

An incremental JSON parser for handling JSON data generated by LLMs.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ijp-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ijp-1.0.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ijp-1.0.0.tar.gz.

File metadata

  • Download URL: ijp-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for ijp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b8aec05c6b77f0a5b7ad5b0f607154c42362a6eeaeb28ee7b59207e42c66fc02
MD5 60813b79a205bef840f4f70f73ae8502
BLAKE2b-256 5daea8c04d07efc6f0f652cb39c2e273477ba01a67531bdc93078ec9a7054ccd

See more details on using hashes here.

File details

Details for the file ijp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ijp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for ijp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02dbfbc17df41b2b4e3aa3c587e3cd1d59c7de2356d5b21bf3713495b02397d7
MD5 ddcc3962df8c02141efcb64a7c182e28
BLAKE2b-256 a9f0464f7b7d5b781c25dad7a162988a90b89535829a0e0f567795b79a896cf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page