Main
Adopt json_repair as a safety net for structured pipelines:
- Keep your normal
json.loads()path, but swap tojson_repair.loads()where inputs are model-generated. - Log both the raw input and the repaired output for debugging and regression tests.
- If you validate schemas, run repair before schema validation so the validator sees a real JSON object.
This is especially useful when you require strict JSON for downstream tools (DB inserts, config generation, API calls).
README excerpt (verbatim)
English | 中文
json_repair
Repair malformed JSON from LLMs, APIs, logs, and user input in Python.
- Fix missing quotes, commas, brackets, comments, stray prose, and truncated values.
- Use it as a drop-in fallback for
json.loads()or as a schema-guided repair step. - Install with
pip install json-repairor try the live demo.

Quick example
import json_repair
bad_json = '{"users":[{"name":"Ada","role":"admin",}],"ok":tru'
decoded_object = json_repair.loads(bad_json)
# {'users': [{'name': 'Ada', 'role': 'admin'}], 'ok': True}If json_repair saves you time, star the repository so more people can find it.
Demo
If you are unsure whether this library will fix your specific problem, or simply want your JSON validated online, try one of these:
- Live demo: https://mangiucugna.github.io/json_repair/
- Audio overview: NotebookLM introduction
Premium sponsors
- Icana-AI Makers of CallCoach, the world's best Call Centre AI Coach. Visit https://www.icana.ai/
- mjharte
Think about sponsoring this library!
This library is free for everyone and is maintained as a side project, so if it helps your work, consider becoming a sponsor: https://github.com/sponsors/mangiucugna
Motivation
Some LLMs are a bit iffy when it comes to returning well formed JSON data, sometimes they skip a parentheses and sometimes they add some words in it, because that's what an LLM does. Luckily, the mistakes LLMs make are simple enough to be fixed without destroying the content.
FAQ
Q: Does it replace json.loads()?
A: It can—README describes using it as a drop-in fallback or replacement for json.loads()/json.load().
Q: What inputs is it best for? A: Model-generated JSON that may include trailing commas, missing quotes, comments, or stray text.
Q: How do I install it?
A: Install with pip install json-repair (or pipx install json-repair) per README.