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

Wrong result when parsing json with trailing texts. #32

Closed liangjs closed 5 months ago

liangjs commented 5 months ago

Describe the bug Wrong result when parsing json with trailing texts.

To Reproduce The following code should return {'a': '', 'b': [{'c': 1}]}

json_repair.loads("""{"a": "", "b": [ { "c": 1} ]}```""")
# This is parsed to {'a': ', "b'}

json_repair.loads("""{    "a": "",    "b": [ { "c": 1} ] \n}```""")
# This will raise exception TypeError: unhashable type: 'list'
liangjs commented 5 months ago

It seems the TypeError exception is not related to the trailing texts, considering:

json_repair.loads("""{    "a": "",    "b": [ { "c": "1as\\\\df"} ] }""", skip_json_loads=True)