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

repair_json throws an error when a single ']' is missing #24

Closed ftudisco closed 6 months ago

ftudisco commented 6 months ago

Describe the bug I am getting an error when trying to repair a small json file with one single issue: a missing ']'

To Reproduce Just run the following code

from json_repair import repair_json

str = '''
{
  "resourceType": "Bundle",
  "id": "1",
  "type": "collection",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "1",
        "name": [
          {"use": "official", "family": "Corwin", "given": ["Keisha", "Sunny"], "prefix": ["Mrs."},
          {"use": "maiden", "family": "Goodwin", "given": ["Keisha", "Sunny"], "prefix": ["Mrs."]}
        ]
      }
    }
  ]
}
'''
repair_json(str, skip_json_loads=True)

Observations The problem seems to be the fact that "name" is made of two dicts. If you remove the second entry, and simply input

 "name": [
          {"use": "official", "family": "Corwin", "given": ["Keisha", "Sunny"], "prefix": ["Mrs."}
]

seems to work