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

Quote problem - failed JSON #12

Closed michalkkkd closed 9 months ago

michalkkkd commented 9 months ago

First of all, thank you for this amazing library! Just wanted to report a case, I got on my 10th try. Describe the bug ChatGPT returned the following string (I'm using JSON function call method, while using their API) { "content": "[LINK]("https://google.com")" }

To Reproduce Steps to reproduce the behavior:

  1. Try to fix this string, using json_repair

Expected behavior String should be fixed to: { "content": "[LINK](https://google.com)" } or similar

Additional context I'm using the latest version Traceback (line numbers may differ): `[1930] Failed to execute script 'jsonfix' due to unhandled exception! Traceback (most recent call last): File "jsonfix.py", line 281, in repair_json File "json/init.py", line 348, in loads File "json/decoder.py", line 337, in decode File "json/decoder.py", line 353, in raw_decode json.decoder.JSONDecodeError: Expecting ',' delimiter: line 2 column 20 (char 22)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "jsonfix.py", line 310, in File "jsonfix.py", line 283, in repair_json File "jsonfix.py", line 17, in parse File "jsonfix.py", line 29, in parse_json File "jsonfix.py", line 106, in parse_object File "jsonfix.py", line 59, in parse_json ValueError: Invalid JSON format`

mangiucugna commented 9 months ago

Hi!

Thanks for reporting this, I have added a corner case to manage this, it's not a general solution but rather managing this specific case because it's impossible to generalize a case like this.

I will release 0.6.0 to support this

michalkkkd commented 9 months ago

Awesome, thank you for ultra fast fix!