CLI ToolsMay 13, 2026·3 min read

json_repair — Fix Malformed LLM JSON in Python

json_repair repairs broken JSON from LLMs, logs, and APIs (missing quotes, commas, brackets) and can replace json.loads() with a safe fallback.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 94/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Cli
Install
Pip|Pipx
Trust
Trust: Established
Entrypoint
pip install json-repair
Universal CLI install command
npx tokrepo install 5c8b9d40-3b3d-5043-87e4-a60e552b6127
Intro

json_repair repairs malformed JSON that LLMs often produce (trailing commas, missing quotes, stray prose) and can replace json.loads() as a safe fallback. The repo is GitHub-verified at 4,853★ and includes a quick Python example.

Best for: LLM apps that rely on JSON outputs (tool calls, structured extraction, ETL) and need a reliable fallback parser

Works with: Python 3.10+; pip/pipx; integrates as a drop-in replacement for json.load(s)

Setup time: 2–5 minutes

Key facts (verified)

  • README states it can be a drop-in fallback for json.loads()/json.load().
  • README lists Python 3.10+ and pip install json-repair.
  • README shows it fixes malformed literals like truTrue during repair.
  • GitHub: 4,853 stars · 195 forks; pushed 2026-05-12 (GitHub API verified).

Main

Adopt json_repair as a safety net for structured pipelines:

  • Keep your normal json.loads() path, but swap to json_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)

PyPI Python version PyPI downloads PyPI Downloads Github Sponsors GitHub Repo stars

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-repair or try the live demo.

banner


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:

Premium sponsors


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.

🙏

Source & Thanks

Source: https://github.com/mangiucugna/json_repair > License: MIT > GitHub stars: 4,853 · forks: 195

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets