Skip to content
JSON Tidy

JSON repair: fix broken JSON

Paste JSON that won’t parse and get a valid version back. Each change is listed and the edited lines are highlighted, so you can check the result before you use it.

Fix your JSON

Runs in your browser. Nothing is uploaded.

What it fixes

ProblemBeforeAfter
Single quotes and unquoted keys{name: 'Maya'}{"name": "Maya"}
Trailing commas["a", "b",]["a", "b"]
Missing commas{"a": 1 "b": 2}{"a": 1, "b": 2}
Comments{"port": 8080 /* dev */}{"port": 8080}
Python’s True and None, JavaScript’s undefined{"ok": True, "x": undefined}{"ok": true, "x": null}
Curly quotes from Word or a Mac{“name”: “Maya”}{"name": "Maya"}
Unclosed brackets and strings{"tags": ["a", "b{"tags": ["a", "b"]}

Everything else is left as written. Long IDs like 12345678901234567890 keep every digit, where running the text through JSON.parse would round them.

JSON from ChatGPT and other AI models

Chat replies usually wrap JSON in a ```json code block, often with a sentence before or after it. Paste the whole reply: the repair takes the JSON out of the block and leaves the rest behind, as in the example above.

If a reply stops partway through, usually because it hit the model’s output limit, the repair closes the open strings and brackets so the JSON parses. The data after the cut-off isn’t recovered, though, so the last item will be incomplete. In your own code, check whether the reply was cut off before parsing it. The unexpected end of JSON input guide shows how for OpenAI’s and Anthropic’s APIs.

What it can’t fix

  • An HTML page. If the text starts with <!DOCTYPE, a server sent a web page instead of JSON, and there’s nothing to repair. See Unexpected token '<'.
  • Missing data. Closing a cut-off document makes it valid, but it can’t restore what was never sent.
  • Wrong values. The repair fixes syntax, not data. A price stored as "12" instead of 12 is valid JSON, so it stays. To check fields and types, use the JSON Schema validator.
  • Ambiguous mistakes. When something could be fixed two ways, such as a quote that might end a string or be part of it, the repair picks one. Read the highlighted lines before you use the result.

If you have an error message from your own code instead, the JSON error lookup explains what it means and where to look.

Repairing JSON in code

The repair on this page is built on jsonrepair, an open-source library by Jos de Jong. You can use it directly in JavaScript, and json_repair does a similar job in Python:

// JavaScript (npm install jsonrepair)
import { jsonrepair } from "jsonrepair";
const data = JSON.parse(jsonrepair(text));

# Python (pip install json-repair)
from json_repair import repair_json
data = json.loads(repair_json(text))

They’re most useful for text you can’t get fixed at the source, like AI output. If an API sends broken JSON, tell whoever runs it. Repairing every response hides a bug that will break other clients too.