Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Quotes are not added after the last value in a JSON when the value has a Comma #73

Closed
strentom opened this issue Sep 27, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@strentom
Copy link

Version of the library

0.29.5

Describe the bug

A quote is not added after the last value in a JSON when there is a comma (,) in the value.

How to reproduce

This:
json_repair.loads("""{\n"response": "Hello Looks like .. , but not ...}\n""")
is parsed into: {'response': 'Hello Looks like ..'}, truncating everything after the comma.

When you remove the comma, the JSON is parsed correctly and a quote (") is added before the }.

Expected behavior

This:
json_repair.loads("""{\n"response": "Hello Looks like .. , but not ...}\n""")
Results in this correct parsed dictionary:
{'response': 'Hello Looks like .. , but not ...'}

@strentom strentom added the bug Something isn't working label Sep 27, 2024
@mangiucugna
Copy link
Owner

Hi! This type of corner case is always a bit hard to handle. I found a workaround but it will work only if it's the last element of the object, otherwise the behavior will be the same as you reported. This is because is virtually impossible to understand if the LLM is writing gibberish or not if it's in the middle of an object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants