{"library":"json-repair","title":"JSON Repair","description":"json-repair is a Python library designed to automatically fix malformed or invalid JSON strings, making them parseable by standard JSON parsers. It addresses common issues like missing quotes, trailing commas, and incomplete structures, making it particularly useful for processing data from less strict sources like LLMs or web scraping. The library is actively maintained with frequent minor releases addressing bug fixes and performance improvements. The current version is 0.58.7.","status":"active","version":"0.58.7","language":"en","source_language":"en","source_url":"https://github.com/mangiucugna/json_repair/","tags":["json","repair","validation","llm","data-cleaning","parsing"],"install":[{"cmd":"pip install json-repair","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required Python version.","package":"python","optional":false}],"imports":[{"symbol":"repair_json","correct":"from json_repair import repair_json"},{"note":"The primary repair function is `repair_json`. `loads` is a convenient drop-in replacement for `json.loads` that includes repair logic. Directly calling a non-existent `repair_json_string` method is a common typo.","wrong":"import json_repair; repaired_data = json_repair.repair_json_string(my_string)","symbol":"loads","correct":"from json_repair import loads"}],"quickstart":{"code":"from json_repair import repair_json, loads\nimport json\n\nbroken_json_string = \"\"\"{ \n  'name': 'Alice', \n  age: 30, \n  'isStudent': True,\n  'hobbies': ['reading', 'gaming',],\n}\"\"\"\n\n# Using repair_json to get a fixed JSON string\nrepaired_string = repair_json(broken_json_string)\nprint(f\"Repaired string: {repaired_string}\")\nparsed_data = json.loads(repaired_string)\nprint(f\"Parsed data (using json.loads): {parsed_data}\")\n\n# Using loads for direct parsing to Python object\n# This method already includes the repair logic internally\nparsed_data_direct = loads(broken_json_string)\nprint(f\"Parsed data (using json_repair.loads): {parsed_data_direct}\")","lang":"python","description":"The quickstart demonstrates repairing a malformed JSON string using both `repair_json` to get a valid string and `loads` for direct parsing into a Python object."},"warnings":[{"fix":"Carefully review the output when using `schema_repair_mode='salvage'`. Consider if `standard` mode or manual post-processing is more appropriate for strict schema adherence. Always test with representative malformed inputs.","message":"The `schema_repair_mode='salvage'` option, introduced in v0.58.0, prioritizes data recovery but might yield an output that is not fully compliant with the provided JSON schema. There have been past regressions (fixed in v0.58.4) where `salvage` mode repaired less aggressively than `standard` mode.","severity":"gotcha","affected_versions":">=0.58.0"},{"fix":"Be aware of potential type coercions when providing a `schema` parameter. If strict validation without modification is needed, consider validating the output separately or using an older version if possible, though this is not recommended. The library's focus is on repair and usability.","message":"Starting from v0.57.1, valid JSON input that does not conform to an optionally provided JSON schema may be *coerced* to match the schema's types (e.g., a string '1' might become an integer 1). This can alter data types in ways that might be unexpected if strict validation without coercion was desired.","severity":"breaking","affected_versions":">=0.57.1"},{"fix":"Simply call `json_repair.repair_json()` or `json_repair.loads()`. If you are certain the input is invalid and want to skip the initial `json.loads()` attempt for performance reasons, pass `skip_json_loads=True`.","message":"By default, `json-repair` first attempts to parse the input using Python's standard `json.loads()`. Only if this fails does it proceed with its repair logic. Explicitly wrapping `json.loads()` in a `try...except` block before calling `json_repair.repair_json()` is redundant and an anti-pattern.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `strict=True` when you need stricter validation and clear error messages for structural problems, accepting that some malformed JSON that would otherwise be repaired will instead raise an error. For maximum repair capability, omit `strict=True` (default is `False`).","message":"The `strict=True` parameter changes the repair behavior to be more validation-oriented. In strict mode, the parser raises a `ValueError` for structural issues like duplicate keys, missing separators, or multiple top-level elements, rather than attempting to fix them. This results in less aggressive repair.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to version 0.58.5 or newer for substantial performance gains when repairing JSON.","message":"Versions prior to v0.58.5 had significantly lower parser performance, especially for common JSON strings. v0.58.5 introduced a 60% improvement.","severity":"gotcha","affected_versions":"<0.58.5"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}