Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsMay 13, 2026·3 min de lectura

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.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Asset
Comando de instalación directa
npx -y tokrepo@latest install 5c8b9d40-3b3d-5043-87e4-a60e552b6127 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introducción

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.

🙏

Fuente y agradecimientos

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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados