json_repair fixes broken JSON from LLMs, logs, and user input in Python. It adds missing quotes and punctuation, can replace json.loads, and supports schema-guided repair.
Overview
json_repair parses and fixes malformed JSON strings that would fail strict json.loads. It targets missing quotes, stray commas, broken brackets, embedded comments, truncated values, and similar syntax damage common in LLM output.
The repair_json function returns corrected text, while loads and load mirror the standard library API so callers can try strict parsing first and fall back automatically. A fromfile helper reads UTF-8 files, and a CLI can process streams from the command line.
Schema-guided repair can steer fixes when a JSON Schema is supplied. Options such as ensure_ascii control whether non-Latin characters stay readable in the output string.
Install with pip install json-repair. A hosted demo lets you test samples before integrating the library.
Key features
- Repair common JSON syntax mistakes
- loads and load drop-in style APIs
- Schema-guided repair option
- Handles comments and stray prose
- Python tuple to JSON array conversion
- UTF-8 file and stream reading
- CLI for batch file repair
Use cases
- Salvage broken JSON from LLM responses
- Harden log ingestion pipelines
- Validate user JSON with automatic cleanup