DEV.co
AI Frameworks · mangiucugna

json_repair

json_repair is a Python library that fixes malformed JSON from LLMs, APIs, logs, and user input by repairing syntax errors like missing quotes, commas, and brackets. It works as a drop-in replacement for json.loads() or as a standalone repair tool with optional schema validation.

Source: GitHub — github.com/mangiucugna/json_repair
5k
GitHub stars
205
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorymangiucugna/json_repair
Ownermangiucugna
Primary languagePython
LicenseMIT — OSI-approved
Stars5k
Forks205
Open issues0
Latest releasev0.61.2 (2026-07-05)
Last updated2026-07-05
Sourcehttps://github.com/mangiucugna/json_repair

What json_repair is

The library provides repair_json(), loads(), and load() functions that attempt stdlib json.loads() first, then fall back to a custom repair parser for invalid JSON. It supports streaming, Pydantic schema validation, non-Latin characters, and offers performance tuning via skip_json_loads and strict modes.

Quickstart

Get the json_repair source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/mangiucugna/json_repair.gitcd json_repair# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

LLM Output Parsing

Fix incomplete or malformed JSON returned by language models that occasionally omit quotes, commas, or closing brackets while preserving semantic content.

Log Aggregation and ETL

Process JSON from diverse API sources, logs, and data pipelines where formatting may be inconsistent or partially corrupted.

User Input Validation

Accept and repair imperfect JSON from user submissions, CLI input, or third-party systems before storing or processing downstream.

Implementation considerations

  • Requires Python 3.10+; verify your runtime supports this minimum version.
  • By default, json_repair validates with stdlib json.loads() first, then repairs only on failure; use skip_json_loads=True only if input is known to be invalid, as the repair parser may alter valid JSON.
  • For non-ASCII characters (Chinese, Japanese, Korean), pass ensure_ascii=False to preserve characters instead of converting to Unicode escapes.
  • The repair parser may infer reasonable defaults (null, empty strings) for missing values; use strict=True if you need the parser to error on ambiguous input instead.
  • Integrate with Pydantic or json-schema for schema-guided repair; the library accepts json.dumps() parameters for serialization control.

When to avoid it — and what to weigh

  • Strict Data Integrity Requirements — If you cannot tolerate any automatic 'guessing' at corrections, json_repair's default behavior of inferring missing values (null, empty strings) may introduce unintended changes.
  • High-Performance Streaming JSON — For very large JSON streams where every millisecond matters, the fallback repair parser overhead may be noticeable; pre-validation or custom parsing may be faster.
  • Heavily Custom JSON Semantics — If you need non-stdlib JSON behavior or support for exotic formats, this library is built on Python's standard json module and may not suit specialized use cases.
  • Zero Data Loss Scenarios — When truncated or incomplete JSON cannot be safely auto-completed (e.g., financial records), the library's auto-completion defaults may mask missing critical data.

License & commercial use

MIT License. Permissive, OSI-approved license allowing unrestricted use, modification, and distribution in commercial and private projects, with no warranty.

MIT is a permissive OSI license with no restrictions on commercial use. You may use json_repair in proprietary software, SaaS, and closed-source products without licensing fees or attribution requirements. Review your own license compliance obligations.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

json_repair parses untrusted JSON input. Consider: the repair parser may accept and 'fix' ambiguous inputs, potentially masking malformed or malicious structures; always validate the output against an expected schema before use. No security audit status is documented. For sensitive data (PII, credentials), ensure repair operations do not introduce unintended exposure of truncated or incomplete values.

Alternatives to consider

rapidjson / orjson

High-performance JSON parsing, but do not repair malformed JSON; best used as a strict first-pass parser with json_repair as a fallback.

jsonschema + manual validation

Schema-driven validation without automatic repair; useful if you need to reject invalid input instead of guessing at corrections.

LLM prompt engineering

Prevent malformed JSON at the source by improving LLM prompts and output constraints; eliminates the need for repair altogether.

Software development agency

Build on json_repair with DEV.co software developers

Integrate json_repair with pip install json-repair and start repairing malformed JSON in minutes. See the live demo or check GitHub for examples.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

json_repair FAQ

Does json_repair guarantee the repaired JSON matches the original intent?
No. The library makes reasonable guesses (adding missing commas, quotes, brackets) but cannot infer truncated values or missing semantic data. Always validate the output against a schema or expected structure.
Will json_repair slow down my code if I pass valid JSON?
Minimally, by default. The library tries stdlib json.loads() first (fast path), then repairs only on failure. For known-invalid input, pass skip_json_loads=True to skip that validation step.
Can I use json_repair with Pydantic?
Yes. Repair the JSON string first with json_repair.loads(), then pass the result to a Pydantic model constructor, or use repair_json(return_objects=True) to get a Python object directly.
What happens if the JSON is too broken to repair?
By default, repair_json() returns an empty string or empty object. Pass strict=True to raise an error instead of silently returning an empty result.

Work with a software development agency

Need help beyond evaluating json_repair? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and ai frameworks integrations — and maintain them long-term.

Ready to handle imperfect JSON?

Integrate json_repair with pip install json-repair and start repairing malformed JSON in minutes. See the live demo or check GitHub for examples.