How to use the JSON repair tool
- Paste the broken text into the JSON to repair box, or select Example to load a sample with an unquoted key and a trailing comma.
- Select Repair JSON to run the repair.
- Read the corrected document in the Result box. It is valid JSON indented with two spaces.
- Compare the result with your input before you use it, because some fixes are guesses.
- Select Copy to put the repaired JSON on your clipboard.
How JSON repair works
A strict parser such as JSON.parse stops at the first character that breaks the grammar in RFC 8259. A repair parser reads the same text with a tolerant grammar. When it meets something illegal that has an obvious meaning, it writes the legal equivalent and keeps going.
This tool then checks the repaired text with a strict parse and reformats it. The formatter works on the text tokens, not on parsed values, so numbers keep the exact digits you supplied. A long integer such as 9007199254740993 or a value written as 1.0 comes out unchanged.
A worked example with model output
The input below has a comment, an unquoted key, single quotes, Python literals, a missing comma between array items, a trailing comma and no closing brace. All of it is repaired in one pass.
Input:
{
// model output
user: 'Ada',
"active": True,
"roles": ["admin" "dev",],
"note": None
Result:
{
"user": "Ada",
"active": true,
"roles": [
"admin",
"dev"
],
"note": null
}Problems the repair fixes
The tool handles the cases below. Each one was confirmed on sample input.
- Single quotes and curly typographic quotes around keys and strings become straight double quotes.
- Unquoted keys are quoted, and missing commas or colons between items are inserted.
- Trailing commas, // line comments and /* block */ comments are removed.
- Python and JavaScript literals are mapped: True, False and None become true, false and null, and undefined becomes null.
- Truncated input is closed. Missing brackets, braces and closing quotes are added, and a key with no value gets null.
- Markdown code fences and a JSONP wrapper such as callback(...) are stripped.
- Unescaped double quotes and raw line breaks inside a string are escaped.
When a repair changes meaning or fails
A repair is an informed guess, so review the output. Values that JSON cannot represent are kept as strings: NaN becomes "NaN", 0x1F becomes "0x1F" and a number with a leading zero such as 01 becomes "01". Several objects separated by line breaks are wrapped in one array. Prose in front of the JSON is not discarded either. A sentence such as Here is the JSON: turns into a string, and the result is an array holding that string and your object.
Some input is too ambiguous and returns an error with a character position. Examples are an empty box, two commas in a row, and two objects on one line with nothing between them.
Frequently asked questions
How do I fix invalid JSON from ChatGPT or another LLM?
Paste the model's reply into the box and select Repair JSON. Code fences, single quotes, Python-style True and None, trailing commas and a cut-off ending are corrected. Remove any explanatory sentences first, or they will appear as strings in the output.
Can it fix truncated JSON?
Yes, structurally. Open strings, arrays and objects are closed and a dangling key receives null. The data that was cut off is gone, so the result parses but may be incomplete.
Does the repair change my numbers?
No. Valid number literals are copied as text, so large integers, exponents and trailing zeros survive exactly. Only literals that are not legal JSON, such as hexadecimal or leading-zero values, are converted to strings.
Is my JSON sent to a server?
No. Repair and formatting run as JavaScript inside this page. The text you paste stays in the browser tab.
What is the difference between JSON repair and a JSON formatter?
A formatter requires valid input and only changes whitespace. Repair accepts invalid input, rewrites it into valid JSON and then indents it. If your document already parses, use the JSON formatter.
Why did I get an error instead of repaired JSON?
The parser could not find a sensible reading. Typical triggers are empty input, doubled commas and adjacent objects on the same line. The message includes the character position of the problem.