# mangiucugna/json_repair

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/mangiucugna-json-repair).**

4,521 stars · 173 forks · Python · mit

## Links

- GitHub: https://github.com/mangiucugna/json_repair
- Homepage: https://pypi.org/project/json-repair/
- awesome-repositories: https://awesome-repositories.com/repository/mangiucugna-json-repair.md

## Topics

`deep-learning` `gpt-4` `json` `llama3` `llm` `machine-learning` `mistral` `openai-api` `parser` `repair`

## Description

json_repair is a Python library that automatically fixes common JSON syntax errors, such as trailing commas, missing quotes, unclosed brackets, and stray text, producing valid JSON output. It can also complete broken structures by closing unclosed arrays and objects, and fill missing values with sensible defaults like empty strings or null.

The library distinguishes itself by handling JSON from large language model outputs, stripping markdown fences, comments, and surrounding prose before parsing. It supports schema-guided repairs, using a JSON Schema to fill missing values, coerce data types, and remove disallowed fields. Additionally, it can process streaming or partial JSON, maintaining a stable best-effort object as new data arrives, and offers strict validation that raises errors on structural issues like duplicate keys.

json_repair provides a command-line interface for fixing JSON files or standard input, with options for strict mode, schema guidance, and output formatting. It also logs each modification made during repair for auditing and debugging, and can skip initial validation to go straight to the repair parser for known-bad input.

## Tags

### Development Tools & Productivity

- [JSON Syntax Repair](https://awesome-repositories.com/f/development-tools-productivity/json-syntax-repair.md) — Fixes common JSON syntax errors such as trailing commas, missing quotes, and unclosed brackets. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))
- [Structural Token Completion](https://awesome-repositories.com/f/development-tools-productivity/automatic-code-formatters/structural-token-completion.md) — Automatically inserts missing brackets, commas, and delimiters to complete broken JSON structures. ([source](https://github.com/mangiucugna/json_repair/blob/main/README.zh.md))
- [JSON Repair CLI](https://awesome-repositories.com/f/development-tools-productivity/command-line-interfaces/json-repair-cli.md) — Ships a command-line interface that reads malformed JSON and writes corrected output. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))
- [LLM Output Repair](https://awesome-repositories.com/f/development-tools-productivity/json-syntax-repair/llm-output-repair.md) — Strips markdown fences, comments, and surrounding prose from LLM responses before parsing embedded JSON. ([source](https://github.com/mangiucugna/json_repair/blob/main/examples/README.md))
- [Schema-Guided Repair](https://awesome-repositories.com/f/development-tools-productivity/json-syntax-repair/schema-guided-repair.md) — Uses a JSON Schema to fill missing values, coerce types, and remove disallowed fields during repair. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))

### Data & Databases

- [JSON Repair Utilities](https://awesome-repositories.com/f/data-databases/json-file-processors/json-repair-utilities.md) — Reads a JSON file, repairs its content, and returns the fixed result as a drop-in file loader. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))
- [Streaming JSON Repairers](https://awesome-repositories.com/f/data-databases/json-file-processors/json-repair-utilities/streaming-json-repairers.md) — Processes partial or incomplete JSON from a stream while keeping the output stable as new data arrives. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))
- [Default Value Fillers](https://awesome-repositories.com/f/data-databases/missing-value-imputation/default-value-fillers.md) — Fills missing JSON fields with sensible defaults like empty strings or null during repair. ([source](https://github.com/mangiucugna/json_repair/blob/main/README.zh.md))

### Part of an Awesome List

- [Fallback Parsers](https://awesome-repositories.com/f/awesome-lists/data/json-parsing/fallback-parsers.md) — Attempts standard JSON parsing first and automatically repairs the input only when strict parsing fails. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))

### Networking & Communication

- [Partial Response Streams](https://awesome-repositories.com/f/networking-communication/response-streaming-utilities/partial-response-streams.md) — Maintains a stable best-effort JSON object from an incomplete streamed response as new data arrives. ([source](https://github.com/mangiucugna/json_repair/blob/main/examples/README.md))

### Software Engineering & Architecture

- [Strict Object Validation](https://awesome-repositories.com/f/software-engineering-architecture/data-schema-validation/data-type-validation/object-shape-validation/strict-object-validation.md) — Raises errors on duplicate keys and missing separators instead of attempting repairs. ([source](https://github.com/mangiucugna/json_repair/blob/main/README.zh.md))
- [JSON Schema Validation](https://awesome-repositories.com/f/software-engineering-architecture/json-schema-validation.md) — Validates repaired JSON against a provided schema to enforce structural constraints. ([source](https://mangiucugna.github.io/json_repair/))
- [Schema-Driven Type Coercers](https://awesome-repositories.com/f/software-engineering-architecture/structural-comparison-tools/comparison-logic-providers/type-coerced-comparisons/schema-driven-type-coercers.md) — Converts values to match a schema's expected type during JSON repair, such as string to integer. ([source](https://mangiucugna.github.io/json_repair/))

### Testing & Quality Assurance

- [Configuration Strictness Validators](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis/strictness-levels/configuration-strictness-validators.md) — Raises errors on structural issues like duplicate keys or missing separators instead of attempting repairs. ([source](https://cdn.jsdelivr.net/gh/mangiucugna/json_repair@main/README.md))
