How do I fix broken JSON from an LLM?

Short answer: Send the broken text to POST /v1/json-repair. It removes code fences and comments, quotes bare keys, converts single quotes, drops trailing commas and closes cut-off output, then returns the parsed JSON and a list of what it fixed. It is deterministic code, not another LLM call, and it is free with no API key.

Try it

curl -X POST https://api-router.instinctagentai.workers.dev/v1/json-repair -H 'content-type: application/json' -d '{"text":"{name: \'Mo\', tags: [1,2,],}"}'

Example result (captured 2026-11-25):

{
  "ok": true,
  "repaired": true,
  "fixes": ["removed code fence", "quoted bare key", "converted quotes to double quotes", "removed trailing comma"],
  "json": { "name": "Mo", "tags": [1, 2] }
}

Over MCP: tool "json_repair" at https://api-router.instinctagentai.workers.dev/mcp, or "fix_broken_json" at https://api-router.instinctagentai.workers.dev/mcp/ask (same function, different name).

Limits

Add an optional "schema" (a common JSON Schema subset) to also get validation errors. It repairs syntax, it cannot recover data that is missing.

All questions. Plain-text version: /ask/how-do-i-fix-broken-json-from-an-llm.md. Some links elsewhere on this site are referral links and are labelled.