How to fix “Invalid JSON”: the 10 most common errors

Guide · Updated July 2026 · ~7 min read

“Unexpected token”, “Unexpected end of JSON input”, “Expecting ',' delimiter” — JSON parsers are strict, and their error messages are famously unhelpful. This guide walks through the ten mistakes that cause almost every invalid-JSON error, shows what each one looks like, and explains how to fix it.

Want the fast path? Paste your document into ourJSON validator — it underlines the exact line and column of the first problem and can auto-fix most of the errors below in one click. Read on if you want to understand why they happen.

1. Trailing commas

The single most common JSON error. JavaScript, Python, and most modern languages allow a comma after the last item in a list — JSON does not.

// ✗ Invalid — comma after the last item
{ "tags": ["api", "config",] }

// ✓ Valid
{ "tags": ["api", "config"] }

This usually creeps in when you delete the last entry of a hand-edited list or paste a snippet from JavaScript source code. Parsers typically report it asUnexpected token ] — pointing at the bracket, not the comma, which is why it’s confusing to hunt down by eye.

2. Single quotes instead of double quotes

JSON strings — both keys and values — must use double quotes. Single quotes are valid in JavaScript and Python, so this error almost always comes from copying a code literal.

// ✗ Invalid
{ 'name': 'Ana' }

// ✓ Valid
{ "name": "Ana" }

3. Unquoted keys

JavaScript object literals allow bare keys like { name: "Ana" }. JSON requires every key to be a double-quoted string.

// ✗ Invalid
{ name: "Ana", age: 31 }

// ✓ Valid
{ "name": "Ana", "age": 31 }

4. Missing commas between items

Every pair in an object and every item in an array must be separated by a comma. This often happens when merging two JSON fragments or adding a property at the end of a line.

// ✗ Invalid — missing comma after "Ana"
{
  "name": "Ana"
  "age": 31
}

Parsers report this as Expected ',' or '}' at the start of thenext key — one line below where the fix actually belongs.

5. Unclosed brackets and braces

Every { needs a matching } and every [ a matching ]. In a deeply nested document a single missing closer produces the dreaded Unexpected end of JSON input — reported at the very last character of the file, far from the actual problem. An editor with bracket matching (or a validator that tracks nesting) finds these in seconds.

6. Unescaped quotes and backslashes inside strings

A literal " inside a string must be written \", and a literal backslash must be \\. Windows file paths are the classic victim:

// ✗ Invalid — backslashes start escape sequences
{ "path": "C:\Users\ana" }

// ✓ Valid
{ "path": "C:\\Users\\ana" }

JSON only recognizes these escapes: \", \\, \/,\b, \f, \n, \r, \t, and\uXXXX. Anything else — like \U or \a — is an error.

7. Comments

Plain JSON has no comments — neither // nor /* */. They’re common because many tools accept “JSON with comments” (JSONC, used by VS Code config files, or JSON5), but a strict parser will reject them. Either remove the comments or, if you control the consumer, switch to a JSONC-aware parser. See ourJSON syntax guide for how JSON, JSONC, and JSON5 differ.

8. NaN, Infinity, and undefined

JSON numbers must be finite decimal numbers, and the only literals are true,false, and null. Values like NaN,Infinity, or undefined come from careless serialization in JavaScript and are invalid. Replace them with null or a sentinel string, and fix the code that produced them.

9. Bad number formats

Some number spellings that languages accept are invalid in JSON:

10. Invisible characters: smart quotes, BOMs, and control characters

The nastiest errors are the ones you can’t see. Word processors and chat apps replace straight quotes with “curly” ones (“ ”), which are not valid JSON string delimiters. Files saved on Windows sometimes start with a byte-order mark (BOM) that some parsers reject. And raw tab or newline characters inside a string must be escaped as\t and \n. A validator that shows the exact column catches all of these instantly — your eyes usually can’t.

Bonus: more than one top-level value

A JSON document holds exactly one value. Two objects back to back —{…} {…} — are invalid. If you have a sequence of records (common in log files, one JSON object per line), that’s a different format calledNDJSON / JSON Lines: valid line by line, but not as a whole file. Wrap the records in an array ([…, …]) if a consumer expects real JSON.

Where invalid JSON actually comes from

Everything above describes symptoms. If you are fixing the same class of error repeatedly, the cause is almost always one of these five, and fixing the cause is faster than fixing the documents:

Fix it in one click

Errors 1–4 and many cases of 6 and 9 are mechanical enough to repair automatically. Paste your document into the Indentio JSON formatter, review the red underline (hover it for the explanation), and press Auto-fix. Everything runs in your browser — nothing is uploaded.

Keep reading