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

[Bug]: Content after quotes is ignored if quotes near curly braces are missing #75

Closed tfshaman closed 2 weeks ago

tfshaman commented 2 weeks ago

Version of the library

0.29.7

Describe the bug

The content before the last quote in JSON is considered the last value in the JSON. The quote is not added after the last value in a JSON if there is another last quote " present in the content.

Can be forced to produce the expected behavior in my case by replacing the { with {" and } with "}.

How to reproduce

This: json_repair.loads('```json{\n"response": "Hello something ... "Some Thing" is something. ...\n}\n```') is parsed into: {'response': 'Hello something ... "Some Thing'}

Expected behavior

This: json_repair.loads('```json{\n"response": "Hello something ... "Some Thing" is something. ...\n}\n```') should be parsed into: {'response': 'Hello something ... "Some Thing" is something. ...'}

which will happen if the the } is replaced by "}.