No project description provided
Project description
json-part
json-part is a lightweight Python library designed to parse and
repair incomplete JSON strings. This library is particularly useful
for handling streaming JSON data, such as the responses from
OpenAI's Large Language Models (LLMs). By enabling the processing
of partial JSON responses, json-part enhances the user experience
by providing immediate, incremental results.
Currently, there is no standard for loading such data, and the project has made many assumptions which, in my opinion, were correct. A fully generic, flexible solution was not prepared. The library code is simple and clear -- requests for contributions, or ideas submitted as an Issue, will be met with all efforts to create the best possible solution.
Features
- Parse Incomplete JSON: Effortlessly convert partial JSON strings into usable Python dictionaries.
- Fix Incomplete JSON: Automatically repair and close open JSON structures to prevent parsing errors.
- Stream-Friendly: Ideal for applications that consume streaming JSON data, improving responsiveness and user interaction.
Installation
To get started with json-part, simply install the package using pip:
pip install json-part
Usage
The json-part library is straightforward to use, with functions
to parse and fix incomplete JSON strings. Here's a quick
example to demonstrate its capabilities:
from json_part import parse_incomplete_json, fix_incomplete_json
if __name__ == '__main__':
# Example of an incomplete JSON string
SAMPLE_1 = """{"status": "o""" # {"status": "o
# Parse the incomplete JSON to a Python dictionary
print(parse_incomplete_json(SAMPLE_1)) # Output: {'status': 'o'}
# Fix the incomplete JSON string
print(fix_incomplete_json(SAMPLE_1)) # Output: {"status": "o"}
# Another example with a slightly more complex incomplete JSON string
SAMPLE_2 = """{"status": "o", "mess""" # {"status": "o", "mess
# Parse and fix operations can handle more complex structures
print(parse_incomplete_json(SAMPLE_2)) # Output: {'status': 'o'}
print(fix_incomplete_json(SAMPLE_2)) # Output: {"status": "o"}
Contributing
Contributions to json-part are welcome!
Whether it's reporting a bug, discussing improvements,
or submitting a pull request, all contributions
help make json-part better for everyone.
License
json-part is released under the MIT License.
See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file json_part-0.1.1.tar.gz.
File metadata
- Download URL: json_part-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1019-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4182124e3a94899938544e41bcfbe7a37284b1109aca9b042bddfe4d65a94f99
|
|
| MD5 |
cd4584730d19d8aa3309cf24c19f9322
|
|
| BLAKE2b-256 |
2674ffed5f6237da9f8c6a9298ce5abd5ae33c8284bd69b28669e38500d14181
|
File details
Details for the file json_part-0.1.1-py3-none-any.whl.
File metadata
- Download URL: json_part-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1019-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
919735311d0192e8e9d132293c91e96ef589c8509a2bb43b54c486aaa40c9a80
|
|
| MD5 |
67730c810e3975c5d96660960eb1129c
|
|
| BLAKE2b-256 |
239aa38b8b84b45a8416ca096050e64f730feb5362681349fc6dbae13d0b2344
|