What JSON Repair fixes
Paste anything that is almost JSON and get valid, formatted JSON back:
| Problem | Example | Repaired |
|---|---|---|
| Trailing commas | [1, 2, 3,] |
[1, 2, 3] |
| Single quotes | {'name': 'Ada'} |
{"name": "Ada"} |
| Unquoted keys | {name: "Ada"} |
{"name": "Ada"} |
| Comments | {"a": 1 // note} |
{"a": 1} |
| Python literals | {"ok": True, "x": None} |
{"ok": true, "x": null} |
| Missing commas | {"a": 1 "b": 2} |
{"a": 1, "b": 2} |
| Truncated output | {"items": [{"id": 1}, {"id": 2 |
{"items": [{"id": 1}, {"id": 2}]} |
| Chat reply | “Here you go:” followed by a fenced json block | just the JSON |
If the input is already valid, the status bar says so and the JSON is simply formatted. Use Indent to choose 2 spaces, 4 spaces, tabs or Minify.
Prose after an unfenced JSON value, such as “…} Hope this helps!”, is stripped too, and the status bar reads “Repaired · stripped surrounding text”. Trailing text that looks like JSON — quotes, colons or brackets — is left in place so a truncated value is never cut off. If the repair then fails, delete the extra text by hand.
Why LLM output breaks JSON
Language models generate text token by token. Even when asked for JSON, they sometimes:
- wrap the answer in a Markdown code block and add a sentence before it,
- switch to Python-style
TrueandNone, - stop mid-object when the response hits the
max_tokenslimit, - add comments or trailing commas that JavaScript accepts but JSON does not.
JSON.parse rejects all of these. Repairing is usually faster and cheaper than re-running the request.
A workflow for model output
A reliable routine for LLM responses is repair, check, then validate in code:
- Paste the raw reply here and confirm the status bar says “Repaired” or “Already valid JSON — nothing to repair”.
- If you’re unsure what changed, paste the original and the repaired text into Text Diff to see every edited line, or browse a large result in the JSON Viewer.
- Generate a runtime validator from the repaired sample with JSON to Zod or JSON to Pydantic, so the next malformed reply is caught by your code instead of by hand.
Other tools that take JSON input, such as the JSON Formatter and the type generators, show a Fix with JSON Repair button in their error panel that opens the broken input here.
Repairing JSON in code
The repair engine is the open-source jsonrepair library:
import { jsonrepair } from 'jsonrepair';
try {
const data = JSON.parse(jsonrepair(llmOutput));
} catch (err) {
// input was too broken to repair
}
In Python, the json-repair package offers a similar function:
from json_repair import repair_json
fixed = repair_json(llm_output)
Validate the repaired data against a schema (for example with Zod or Pydantic) before trusting it.
After repairing
- Check strict syntax and big-number handling in the JSON Formatter.
- Generate types for the payload with JSON to TypeScript.
Frequently asked questions
Can it fix JSON returned by ChatGPT, Claude or Gemini?
Yes — that is the most common use. Paste the whole reply, including the explanation before the JSON and any ```json code fence. The tool extracts the JSON, fixes syntax problems and closes structures that were cut off when the model hit its output limit.
Will repairing change my data?
Repairs are syntactic: quotes, commas, brackets and literals are fixed, and existing values are kept. Truncated input is the exception. Missing brackets are added, a cut-off string is closed where it stops, and a key with no value gets null. Always review the result before relying on it.
Is JSON5 supported?
The common JSON5 features are: unquoted keys, single-quoted strings, trailing commas and comments are converted to strict JSON. NaN, Infinity and hexadecimal numbers have no JSON equivalent, so they come out as strings.
How do I prevent broken JSON from an LLM in the first place?
Use the provider's structured-output or JSON mode, include a JSON Schema in the prompt, and set a max-token limit high enough for the full response. Keep a repair step as a safety net for the cases that still slip through.
Is my data uploaded?
No. The repair runs in your browser, and nothing you paste is uploaded.
Last updated