Skip to content

Parsing ChatGPT JSON stream response — Partial and incomplete JSON parser python library for OpenAI | repair invalid JSON, parse output of LLMs

License

Notifications You must be signed in to change notification settings

iw4p/partialjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PartialJson

Partialjson

Parse Partial and incomplete JSON in python

Parse Partial and incomplete JSON in python with just 3 lines of python code.

PyPI version Supported Python versions Downloads

Example

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

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

$ pip install partialjson

Also can be found on pypi

How can I use it?

  • Install the package by pip package manager.
  • After installing, you can use it and call the library.

Star History

Star History Chart

Issues

Feel free to submit issues and enhancement requests or contact me via 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

About

Parsing ChatGPT JSON stream response — Partial and incomplete JSON parser python library for OpenAI | repair invalid JSON, parse output of LLMs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages