How to Fix Invalid JSON (and Every Tool You Need for It)

JSON breaks for a small, predictable set of reasons. This guide walks through each one with a before/after example, explains what a repair tool should and should not change, and ends with the full directory of tools for whatever you need to do next.

Short version: paste the broken payload into JSON Repair. It fixes the common structural mistakes and returns valid JSON. If you want to know why it broke — and how to stop it happening upstream — read on.

First, confirm it is actually invalid

Before repairing anything, run the payload through JSON Validator. It reports the line and column of the first failure, which is usually enough to identify the cause. Repairing valid JSON is a no-op; repairing JSON you have not read yet can hide a real upstream bug.

A useful distinction: a syntax error means the text is not JSON at all, while a schema error means it is valid JSON that does not match the shape you expected. For the second case use JSON Schema Validator instead.

The errors that break JSON.parse

1. Trailing commas

Legal in JavaScript object literals, illegal in JSON. This is the single most common cause.

{ "a": 1, "b": 2, }      // invalid
{ "a": 1, "b": 2 }       // valid

2. Single-quoted strings

JSON strings must use double quotes. Python's str() and JavaScript console output both produce single quotes, so copied output often fails.

{ 'name': 'Ada' }        // invalid
{ "name": "Ada" }        // valid

3. Unquoted keys

Object keys are strings and must be quoted, even when they look like identifiers.

{ name: "Ada" }          // invalid
{ "name": "Ada" }        // valid

4. Comments

JSON has no comment syntax. JSONC and JSON5 do, which is why config files copied from an editor frequently fail. Strip them before parsing.

{
  // the user record
  "id": 1
}

5. Python and JavaScript literals

JSON defines exactly three bare words: true, false and null. Anything else is a syntax error.

{ "ok": True, "value": None }      // Python  - invalid
{ "ok": true, "value": null }      // JSON    - valid

undefined, NaN and Infinity are also invalid. JSON.stringify silently converts NaN and Infinity to null and drops undefined object properties, so these usually arrive from hand-edited files or non-JavaScript producers.

6. Double-escaped JSON

The trap that wastes the most time. What you have is a JSON string whose contents are themselves JSON — every inner quote is backslash-escaped. It typically comes from a value that was stringified twice, or from a log line that embedded a payload.

"{\"id\":1,\"name\":\"Ada\"}"

Parsing this once returns a string, not an object. Unescape it first with JSON Escape / Unescape, or parse twice. JSON Parse handles the common quoted-payload cases directly.

7. Smart quotes

Payloads pasted from documents, chat apps or email often carry typographic quotes ( and ) instead of the ASCII ". They look almost identical and fail immediately.

8. A byte order mark or stray leading characters

A UTF-8 BOM (U+FEFF) before the opening brace breaks many parsers, as does a stray log prefix or a shell prompt copied along with the payload. If the very first character is not { or [, look there first.

9. A truncated payload

Copying from a terminal that clipped the output, or reading a response that was cut short, leaves unbalanced brackets. A repair tool can close them, but the data is genuinely incomplete — fix the source rather than trusting the patched result.

What a repair tool should and should not do

Automatic repair is only trustworthy with clear limits. The rules our JSON Repair tool follows:

  • Valid JSON is never modified. If the input parses, it is returned unchanged. Repair can never corrupt something that already worked.
  • The output is always valid JSON, because it is re-serialised rather than patched as text.
  • Unrecoverable input returns an honest error instead of a plausible-looking guess.
  • It runs entirely in your browser. Nothing is uploaded, which matters when the payload is a production response.

What it cannot do is invent missing data. Truncated JSON becomes syntactically valid, not complete.

Repair, validate, format or parse?

SituationTool
It will not parse and you want it fixedJSON Repair
You need the exact line and column of the errorJSON Validator
It parses but is unreadableJSON Formatter
It arrived as an escaped or quoted stringJSON Parse
It parses but has the wrong shapeJSON Schema Validator
You need to see the structureJSON Viewer or Visual Editor

After the repair

Once the payload parses, the usual next steps are comparing it against a known-good version with JSON Compare, shrinking it with JSON Minifier, or converting it for someone else to read with JSON to CSV or JSON to Excel.

The complete tool directory

Every tool below runs client-side in your browser. No uploads, no signup.

Core JSON

Compare and diff

Transform and edit

Converters

Code generation

Utilities

FAQs

Why does JSON.parse say "Unexpected token"?

The parser hit a character that is not legal at that position. In practice it is nearly always a trailing comma, a single-quoted string, an unquoted key, or a literal such as True, None, NaN or undefined that JSON does not define.

Are trailing commas allowed in JSON?

No. RFC 8259 does not permit a comma after the final element. JavaScript and JSON5 do, which is why the habit carries over.

Can JSON contain comments?

No. Use JSONC or JSON5 if you need them, and strip comments before handing the text to a standard parser.

What is double-escaped JSON?

A JSON string whose contents are themselves JSON, so every inner quote is backslash-escaped. Unescape once, then parse the result.

Is my JSON uploaded?

No. Every tool here runs in your browser; nothing is uploaded, stored or logged.