mangiucugna / json_repair

A python module to repair invalid JSON, commonly used to parse the output of LLMs
https://pypi.org/project/json-repair/
MIT License
826 stars 48 forks source link

Infinite Loop when the input is `{"` #8

Closed brianineza01 closed 11 months ago

brianineza01 commented 11 months ago

Describe the bug I was trying the json response streaming from openai api and fix it using this library. When the json input was {" it got my program stuck for some reason. After deep investigation, I found it was an infinite loop in this library. Attached below are some screenshots with what's happening and the function that it's happening in. I added some print() in the library code to check what's happening.

To Reproduce Steps to reproduce the behavior:

  1. Import the library
  2. make your JSON string {"
  3. use the repair_json function from the library
  4. You will have a stuck program with an infinite loop.

Expected behavior Should throw an error or have an empty object like {}.

Screenshots CleanShot 2023-11-22 at 07 01 50@2x CleanShot 2023-11-22 at 07 00 37@2x

Desktop (please complete the following information):

mangiucugna commented 11 months ago

Thanks for reporting the bug, I have released 0.4.2 with the fix