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

Function "repair_json" raises an AttributeError exception when called with a certain input #39

Closed werpachowski-msft closed 5 months ago

werpachowski-msft commented 5 months ago

Describe the bug When I call "repair_json" with a certain input, it throws AttributeError in version 0.17.0:

in JSONParser.parse_string(self)

    234     lstring_delimiter = "“"
    235     rstring_delimiter = "”"
--> 236 elif char.isalpha():
    237     # This could be a <boolean> and not a string. Because (T)rue or (F)alse or (N)ull are valid
    238     if char.lower() in ["t", "f", "n"]:
    239         value = self.parse_boolean_or_null()

AttributeError: 'bool' object has no attribute 'isalpha'

To Reproduce

  1. Install json_repair==0.17.0
  2. Execute json_repair.repair_json("[{]", return_objects=True)

Expected behavior Returns "[]"

Desktop (please complete the following information):

Additional context

Bug occurs in 0.17.0 version only