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]: loading an ordinary string results in empty string object #58

Closed xonfour closed 2 months ago

xonfour commented 2 months ago

Version of the library

0.25.3

Describe the bug

Hi there!

Just upgraded from v0.13 to current release and found that loading a raw string does not work anymore:

>>> json_repair.loads('test')
''

I expected

>>> json_repair.loads('test')
'test'

as a fallback. This breaks my setup as I now have to check myself somehow if parameter is just a raw string without any JSON object definition. Is this a bug or are there any good reasons for that change?

Thanks!

How to reproduce

json_repair.loads('test') ''

Expected behavior

json_repair.loads('test') 'test'

mangiucugna commented 2 months ago

hi! Thanks for reporting but this is not a bug. A plain string without quotes is not a valid JSON string and it is ignored by the library to cover for cases like this: Sure here's your JSON {"key":"value"}

So this behavior is a feature not a bug