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
1.16k stars 65 forks source link

Parsing comments with float point number #45

Closed liangjs closed 6 months ago

liangjs commented 6 months ago

Consider the following code:

json_repair.loads("""{ \n "b": "xxxxx" // comment 1.2 \n }""")

It should be {'b': 'xxxxx'}. But the library outputs {'b': 'xxxxx', 0.2: ''}.

liangjs commented 6 months ago

More generally, we can test with this code

json_repair.loads("""{
  "b": "xxxxx", // comment a.b
  "c": "a"
}""")

It produces a weird result {'b': 'xxxxx', '.': 'c": "a'}

mangiucugna commented 6 months ago

Hi, I tried this with the latest version of the library and I couldn't reproduce. I am pushing a fix because I noticed that there is a different edge case but I can't reproduce this specific edge case using latest.

liangjs commented 6 months ago

Thanks. After checking out to the latest version, it is fixed.