AI & LLM

LLM JSON Repair & Schema Validator

Fixes broken LLM JSON output: strips markdown fences, balances brackets, removes trailing commas, fixes single-quoted strings, validates against optional JSON Schema.

POST /api/repair-json
<100ms API Key

Why use JSON Repair?

Large Language Models (LLMs) often produce malformed JSON with markdown code fences, unbalanced brackets, trailing commas, or incorrect data types. This API automatically detects and fixes these issues, returning clean, valid JSON that you can safely parse in your application.

What it does

The LLM JSON Repair API is a specialized tool designed to handle the messy reality of JSON output from Large Language Models. Whether you're using GPT-4, Claude, Llama, or any other LLM, this API ensures you get clean, parseable JSON every time.

Key Features

  • Markdown Fence Removal: Strips ```json and ``` wrappers that LLMs often include
  • Bracket Balancing: Automatically closes unclosed braces, brackets, and parentheses
  • Trailing Comma Cleanup: Removes trailing commas that break JSON parsers
  • Type Coercion: Converts string numbers to actual numbers, fixes boolean representations
  • Schema Validation: Optional JSON Schema validation to ensure output meets your requirements

Code Examples

curl -X POST https://api.atomicapis.dev/api/repair-json \\
  -H "X-RapidAPI-Proxy-Secret: YOUR_SECRET" \\
  -H "Content-Type: application/json" \\
  -d '{
    "text": "{name: '\''John'\'', age: 30, }",
    "schema": null
  }'

Request Parameters

Name Type Required Description
text string Required The broken JSON string to repair
schema string Optional JSON Schema to validate the repaired output against

Repair Operations

All applicable repairs are applied automatically: strips markdown code fences, extracts JSON from surrounding text, removes comments, removes control characters, fixes single-quoted strings to double-quoted, removes trailing commas, and balances unclosed brackets/braces.

Response Format

200 OK - Success Response
{
  "repairedJson": "{\"name\":\"John\",\"age\":30}",
  "wasModified": true,
  "repairsApplied": [
    "Fixed single-quoted strings to double-quoted",
    "Removed trailing commas"
  ],
  "schemaValid": null,
  "schemaErrors": []
}
Field Type Description
repairedJson string The repaired JSON as a string.
wasModified boolean Indicates whether the original input had issues that required fixing.
repairsApplied array List of repair operations performed (e.g., "Removed trailing commas", "Balanced unclosed brackets/braces").
schemaValid boolean | null Whether the repaired JSON passes schema validation. Returns null if no schema was provided.
schemaErrors array Array of validation error messages if schema validation failed.

Use Cases

LLM Output Cleaning

Clean up JSON responses from GPT-4, Claude, or other LLMs before parsing. Handles markdown fences, trailing commas, and type inconsistencies automatically.

OpenAI Anthropic Llama

User Input Validation

Accept JSON from users or external systems with lenient parsing. Repair common mistakes while validating against your schema for data integrity.

Forms APIs Imports

Legacy Data Migration

Migrate data from legacy systems with inconsistent JSON formatting. Repair malformed exports and validate structure before importing to modern databases.

ETL Migration Cleanup

Build Constraints

Implementation

  • Pure text processing — regex extraction, bracket balancing, schema validation
  • No ML models required — deterministic repair algorithms
  • Sub-100ms response time for typical inputs

Compatibility

  • Model-agnostic — works with any LLM output
  • Framework-agnostic — use with any tech stack
  • JSON Schema Draft 7+ compatible

Error Codes

Code Status Description
INVALID_JSON 400 The input could not be parsed as JSON even after repair attempts.
SCHEMA_VALIDATION_FAILED 400 The repaired JSON does not match the provided schema.
MISSING_REQUIRED_FIELD 400 The text field is required.
INVALID_SCHEMA 400 The provided JSON Schema is invalid or malformed.
RATE_LIMIT_EXCEEDED 429 Too many requests. Please slow down and try again.

Ready to fix your JSON?

Start using the LLM JSON Repair API today. Get your API key and integrate in minutes.

MCP Integration MCP Ready

What is MCP?

Model Context Protocol (MCP) allows AI assistants like Claude to call this API as a native tool during conversation. Instead of writing HTTP requests, the AI invokes the tool directly — no API keys or boilerplate needed on the client side.

Tool Details

Tool Class
JsonRepairTools
Method
RepairJson()

Description

Fixes broken JSON from LLM outputs and validates against a schema