You paste a block of JSON into your code or an API client and it throws Unexpected token or invalid JSON. JSON is strict — one stray character breaks the whole document — but the rules are simple, and almost every error comes down to the same handful of mistakes. Here's what makes JSON invalid and how to fix it in seconds.
What "invalid JSON" really means
JSON has a tight grammar: data is keys and values, keys are double-quoted strings, and values are strings, numbers, true, false, null, arrays or objects. A parser reads the text character by character, and the moment it sees something the grammar doesn't allow, it stops and reports the position. "Invalid JSON" simply means the text broke one of those rules — it doesn't mean your data is wrong, only that the formatting is.
The 8 most common causes
- Trailing commas — a comma after the last item, like
[1, 2, 3,]. JSON forbids it. - Single quotes — JSON requires double quotes, so
'name'must be"name". - Unquoted keys —
{name: "x"}is JavaScript, not JSON; keys need quotes. - Comments —
//and/* */are not allowed in JSON. - Missing or extra brackets — an unclosed
{or[, or a stray closing one. - Wrong booleans — use lowercase
true/false, notTrueorTRUE. - undefined or NaN — these JavaScript values aren't valid JSON; use
nullor a number. - Hidden characters — a byte-order mark (BOM) or smart quotes pasted from a document.
How to find the exact error fast
Instead of hunting line by line, paste your text into the JSON Formatter and click Validate. It uses the browser's native parser and reports the precise position where parsing failed, so you can jump straight to the trailing comma or missing bracket. Click Beautify afterwards to re-indent the document — misaligned nesting often reveals a missing brace at a glance.
How to avoid invalid JSON next time
Generate JSON with a library — JSON.stringify in JavaScript, json.dumps in Python — rather than building strings by hand, so quotes and commas are escaped correctly for you. Keep a formatter handy to validate before you ship a config or payload. And if your data is travelling in a URL or header, pair it with the URL encoder or Base64 encoder; the full set is on the developer tools page.