https://github.com/iw4p/partialjson
Repair invalid LLM JSON, commonly used to parse the output of LLMs — Parsing ChatGPT and llm JSON stream response — Partial and incomplete JSON parser python library for OpenAI | repair invalid JSON, parse output of LLMs
https://github.com/iw4p/partialjson
incompletejson jsonparser llm llmjson openai parser partialjson repair stream-json streaming-json
Last synced: 10 months ago
JSON representation
Repair invalid LLM JSON, commonly used to parse the output of LLMs — Parsing ChatGPT and llm JSON stream response — Partial and incomplete JSON parser python library for OpenAI | repair invalid JSON, parse output of LLMs
- Host: GitHub
- URL: https://github.com/iw4p/partialjson
- Owner: iw4p
- License: mit
- Created: 2023-11-24T13:22:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-24T12:53:39.000Z (about 1 year ago)
- Last Synced: 2025-03-25T09:24:01.267Z (10 months ago)
- Topics: incompletejson, jsonparser, llm, llmjson, openai, parser, partialjson, repair, stream-json, streaming-json
- Language: Python
- Homepage:
- Size: 842 KB
- Stars: 77
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PartialJson
[](https://pypi.org/project/partialjson/)
## Parse Partial and incomplete JSON in python

### Parse Partial and incomplete JSON in python with just 3 lines of python code.
[](https://pypi.org/project/partialjson)
[](#Installation)
[](https://pepy.tech/project/partialjson)
## Example
```python
from partialjson.json_parser import JSONParser
parser = JSONParser()
incomplete_json = '{"name": "John Doe", "age": 30, "is_student": false, "courses": ["Math", "Science"'
print(parser.parse(incomplete_json))
# {'name': 'John', 'age': 30, 'is_student': False, 'courses': ['Math', 'Science']}
```
Problem with `\n`? strict mode is here
```python
from partialjson.json_parser import JSONParser
parser = JSONParser(strict=False)
incomplete_json = '{"name": "John\nDoe", "age": 30, "is_student": false, "courses": ["Math", "Science"'
print(parser.parse(incomplete_json))
# {'name': 'John\nDoe', 'age': 30, 'is_student': False, 'courses': ['Math', 'Science']}
```
### Installation
```sh
$ pip install partialjson
```
Also can be found on [pypi](https://pypi.org/project/partialjson/)
### How can I use it?
- Install the package by pip package manager.
- After installing, you can use it and call the library.
## Star History
[](https://star-history.com/#iw4p/partialjson&Date)
### Issues
Feel free to submit issues and enhancement requests or contact me via [vida.page/nima](https://vida.page/nima).
### Contributing
Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.
1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Update the Version** inside **init**.py
4. **Commit** changes to your own branch
5. **Push** your work back up to your fork
6. Submit a **Pull request** so that we can review your changes