How to Fix Invalid JSON: Commas, Quotes, Comments and Cut-Off Data
The common reasons JSON fails to parse, how to read the error message, and how to repair broken JSON automatically with a list of every fix that was made.

How to Fix Invalid JSON: Commas, Quotes, Comments and Cut-Off Data
"Unexpected token" and "Unexpected end of JSON input" are two of the most familiar error messages in web development. JSON is strict by design: one extra comma or one single quote and the whole document is rejected. That strictness keeps machines in agreement, but it is painful when the JSON came from a hand-edited file, a log line, a chat message or a language model. The free JSON Repair Tool fixes the usual problems automatically and lists every change it made, so you can check them instead of trusting a black box.
The usual suspects
Most broken JSON falls into a handful of patterns:
- Trailing commas after the last item in an object or array, which JavaScript allows but JSON does not.
- Missing commas between items, often after a line was added in an editor.
- Single quotes or smart quotes around strings and keys. Word processors and chat apps turn straight quotes into curly ones without asking.
- Unquoted keys, as written in JavaScript object literals.
- Comments with
//or/* */, common in configuration files. - Python or JavaScript values such as
True,False,None,undefined,NaNandInfinity. - Truncated data, where a response or a log line was cut off before the closing brackets.
How the repair works
The tool reads the text with a tolerant parser that understands all of these forms. When it meets something JSON does not allow, it records a fix, such as "Removed trailing commas", "Replaced single quotes with double quotes" or "Closed unclosed objects and arrays (input was cut off)". The output is standard JSON that any parser accepts, pretty-printed or minified as you prefer.
Values that have no JSON equivalent need a decision. NaN, Infinity, None and undefined all become null, because JSON has no way to represent them. These choices appear in the fix list, so nothing changes silently.
Reading a parse error yourself
If you prefer to fix the source, the error message tells you where to look. A position such as "line 12 column 5" points at the first character the parser could not accept. The real mistake is often just before it: a missing comma at the end of line 11, or a quote that was never closed several lines earlier. The repair tool shows the browser's original parse error above its list of fixes, which helps you learn the patterns.
When repair is not the answer
Automatic repair is excellent for data you are inspecting, test fixtures and one-off conversions. It is not a substitute for fixing the system that produced the broken JSON. If an API returns truncated responses, the cause may be a timeout or a size limit, and repairing the output hides lost data. Treat the "closed unclosed objects" fix as a warning sign that something is missing, not as a solution.
Language model output is a special case. Models often wrap JSON in prose or code fences, use single quotes, or stop mid-object. The tool takes the JSON out of a code fence and drops a sentence of prose before the first bracket, which makes it a quick way to rescue structured output during development; in production, prefer a structured-output mode or schema validation.
Step by step
- Paste the broken JSON or load the file.
- Read the original error to see where the parser stopped.
- Review the list of fixes the tool applied.
- Choose pretty or minified output.
- Copy or download the valid JSON, and validate it against your schema if you have one.
Privacy
Repair runs entirely in your browser, so logs and API payloads that contain personal data or keys never leave your device.



