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.
/api/repair-json
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
```jsonand```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
}'
const response = await fetch('https://api.atomicapis.dev/api/repair-json', {
method: 'POST',
headers: {
'X-RapidAPI-Proxy-Secret': 'YOUR_SECRET',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: "{name: 'John', age: 30, }",
schema: null
})
});
const result = await response.json();
console.log(result.repairedJson);
import requests
response = requests.post(
'https://api.atomicapis.dev/api/repair-json',
headers={
'X-RapidAPI-Proxy-Secret': 'YOUR_SECRET',
'Content-Type': 'application/json'
},
json={
'text': "{name: 'John', age: 30, }",
'schema': None
}
)
result = response.json()
print(result['repairedJson'])
using System.Net.Http.Json;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-RapidAPI-Proxy-Secret", "YOUR_SECRET");
var request = new
{
text = "{name: 'John', age: 30, }",
schema = (string?)null
};
var response = await client.PostAsJsonAsync(
"https://api.atomicapis.dev/api/repair-json",
request
);
var result = await response.Content.ReadFromJsonAsync<RepairJsonResponse>();
Console.WriteLine(result.RepairedJson);
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
{
"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.
User Input Validation
Accept JSON from users or external systems with lenient parsing. Repair common mistakes while validating against your schema for data integrity.
Legacy Data Migration
Migrate data from legacy systems with inconsistent JSON formatting. Repair malformed exports and validate structure before importing to modern databases.
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
JsonRepairTools
RepairJson()
Description
Fixes broken JSON from LLM outputs and validates against a schema