Skip to main content
AI JSONMedic
API Live

JSON Repair API

A simple REST API to fix broken JSON from any AI model. Free, no authentication, CORS enabled. Drop it into your n8n workflow, Python script, or Node.js app.

Quick Start

POST /api/repaircurl
curl -X POST https://aijsonmedic.com/api/repair \
  -H "Content-Type: application/json" \
  -d '{
    "input": "{name: \'Alice\', active: True, score: NaN}"
  }'

Endpoint Reference

POST/api/repair

Repairs malformed JSON. Accepts any broken JSON string and returns the fixed version with a full report of changes made.

Request Body

{
"input": "string (required)", // your broken JSON
"options": {
"fixPythonBooleans": true, // default: true
"stripMarkdown": true, // default: true
"fixTruncation": true // default: true
}
}

Limits

  • Max input: 2MB
  • No rate limit (fair use)
  • No authentication

CORS

  • Origin: *
  • Methods: POST, OPTIONS
  • Cache: no-store

Response (200 OK)

JSON
{
  "output": "{\"name\": \"Alice\", \"active\": true, \"score\": null}",
  "valid": true,
  "repaired": true,
  "issues": [
    {
      "type": "UnquotedKey",
      "severity": "error",
      "message": "Unquoted key 'name' → \"name\"",
      "stage": "quotes"
    },
    {
      "type": "SingleQuote",
      "severity": "error",
      "message": "Single-quoted string converted to double quotes",
      "stage": "quotes"
    },
    {
      "type": "PythonBoolean",
      "severity": "error",
      "message": "Python boolean True → true",
      "stage": "python"
    },
    {
      "type": "NaNValue",
      "severity": "error",
      "message": "NaN replaced with null",
      "stage": "values"
    }
  ],
  "summary": "4 issues fixed: 1 unquoted key, 1 single-quote string, 1 Python boolean, 1 NaN value"
}

Response Fields

outputstringRepaired JSON string. Always valid if valid=true.
validbooleantrue if output is valid JSON.
repairedbooleantrue if any changes were made.
issuesarrayEvery change made, with type, severity, and description.
summarystringHuman-readable summary of all repairs.

Error Responses

400Body must include an "input" string field
413Input exceeds 2MB limit
405Method not allowed (use POST)

Integration Examples

JavaScript / Node.js
const response = await fetch('https://aijsonmedic.com/api/repair', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ input: brokenJson }),
});
const { output, valid, issues } = await response.json();
if (valid) {
  const parsed = JSON.parse(output);
  // use parsed data
}
Python
import requests

def repair_json(broken_json: str) -> dict:
    response = requests.post(
        'https://aijsonmedic.com/api/repair',
        json={'input': broken_json},
        timeout=10,
    )
    response.raise_for_status()
    result = response.json()
    if result['valid']:
        return result['output']   # valid JSON string
    raise ValueError(f"Could not repair: {result}")
n8n Workflow (Code Node)
// In n8n HTTP Request node:
// Method: POST
// URL: https://aijsonmedic.com/api/repair
// Body: { "input": "{{ $json.llm_output }}" }
//
// Then parse the response:
const result = $input.first().json;
if (result.valid) {
  return [{ json: JSON.parse(result.output) }];
}
throw new Error('JSON repair failed: ' + result.summary);

What the API Fixes

Markdown code fences

```json wrapper from AI responses

Trailing commas

{a: 1,} → {a: 1}

Single quotes

{name: 'Bob'} → {"name": "Bob"}

Unquoted keys

{name: "Bob"} → {"name": "Bob"}

Python booleans

True/False/None → true/false/null

NaN / Infinity

NaN, Infinity → null

JS comments

// and /* */ removed safely

Truncated JSON

Closes unclosed strings/brackets

Missing commas

{a:1 b:2} → {a:1, b:2}

BOM characters

UTF-8 BOM + zero-width chars stripped

FAQ

Is the JSON repair API free?

Yes. The current API is free with a 2MB input limit. No API key required. A Pro tier with higher limits and dedicated endpoints is planned.

Does the API store my JSON data?

No. The API processes JSON in memory and returns the result immediately. No data is logged, stored, or shared.

What errors can the API fix?

The API fixes: markdown code fences, trailing commas, single quotes, unquoted keys, Python booleans (True/False/None), NaN/Infinity/undefined values, JavaScript comments, truncated JSON, missing commas, and BOM characters.

Need Higher Limits?

Pro plan coming soon: dedicated API endpoint, 50MB limit, API key auth, batch repair, usage dashboard, and priority support.