Invalid JSON: what the error means and how to fix it
JSON parsers are strict on purpose. One character in the wrong place and the whole file is rejected, often with an error that points somewhere confusing. The good news is that almost every case comes down to the same few mistakes.
Short answer
Go to the line and column in the error, then look at the character just before that spot. The cause is almost always one of these: a trailing comma, a missing comma, single quotes, an unquoted key, a comment, an unescaped quote or line break inside a string, several JSON documents in one file, a cut-off file, or something that isn’t JSON at all (usually an HTML error page).
Get Sonnet free Read JSON on your phone, offline.
How to read the error message
Parsers report where they noticed the problem, not where it is. A missing comma on line 3 is usually reported at the start of line 4, when the parser meets a value it didn’t expect. So look at the reported position, then step backwards.
The wording depends on the language. These are the ones you’ll search for most:
| Error you see | Where | Usual cause |
|---|---|---|
Unexpected token < in JSON at position 0 | JavaScript | The response is an HTML page (an error or login page), not JSON |
Unexpected end of JSON input | JavaScript | Empty response or cut-off file |
Expecting property name enclosed in double quotes | Python | Trailing comma, unquoted key or single-quoted key |
Expecting ',' delimiter | Python | Missing comma, or an unescaped quote inside a string |
Expecting value: line 1 column 1 (char 0) | Python | Empty input, or not JSON at all |
Extra data | Python | More than one JSON document in the file (often JSON Lines) |
The nine usual mistakes
1. Trailing comma
{ "a": 1, "b": 2, }
JavaScript allows a comma after the last item, and JSON doesn’t. Fix: delete the comma before } or ]. It’s the most common error in hand-edited files.
2. Missing comma
{ "a": 1 "b": 2 }
Usually happens when a line is added to the end of an object. Fix: add a comma after the item before the reported position.
3. Single quotes
{ "plan": 'pro' }
JSON strings must use double quotes. Fix: replace ' with " around keys and strings. Watch out for apostrophes inside the text.
4. Unquoted keys
{ name: "Ava" }
Valid in a JavaScript object, not in JSON. Fix: wrap every key in double quotes.
5. Comments
{
// retry settings
"retries": 3
}
JSON has no comments. Files like VS Code’s settings.json or tsconfig.json are really JSONC (JSON with comments), and only tools that expect JSONC accept them. Fix: remove the comments, or open the file with a JSONC-aware tool.
6. Unescaped quotes or line breaks inside a string
{ "quote": "She said "hi"" }
A " inside a string ends it early, and a raw line break inside a string isn’t allowed either. Fix: write \" for a quote, \n for a new line and \\ for a backslash. Windows paths are the classic trap: "C:\\Users\\ava".
7. More than one JSON document
{ "event": "open" }
{ "event": "close" }
Log files and exports often hold one JSON object per line. That format is called JSON Lines (.jsonl or .ndjson). Each line is valid, but the file as a whole isn’t a single JSON document. Fix: read it line by line with a JSON Lines tool, or wrap the objects in [ … ] with commas between them.
8. A cut-off file
An interrupted download, a copy that hit a clipboard limit, or a log that was still being written. The error lands at the very end (“Unexpected end of JSON input”). Fix: get the file again. Guessing the missing brackets rarely gives you back the missing data.
9. It isn’t JSON at all
If the error is at position 0 and mentions <, you received HTML: a server error page, a login redirect, or a “file not found” page saved with a .json name. Open the file as text and read the first line. The real problem is the request that produced it. Other culprits at position 0 are an empty file and invisible characters at the start (a byte-order mark added by some Windows editors).
Fixing invalid JSON on a phone
For the most common slips you may not need to touch the text at all. Sonnet repairs them when it opens the file:
- Missing and trailing commas and unclosed brackets are fixed as the file opens. A message tells you it happened, and the repaired JSON is what you see, copy and save. The file on your phone only changes when you tap Save.
- Unquoted keys and single quotes open as they are, and saving writes proper double quotes.
- A cut-off file gets its closing brackets back, so what was downloaded opens. The missing data isn’t recovered: get the file again if you need it.
The rest of the list still needs the raw text: comments, an unescaped quote or line break inside a string, JSON Lines, and anything that isn’t JSON at all. Sonnet says the file isn’t valid JSON instead of guessing. Fix those in a plain text or code editor on Android, or on a computer if the file is long, then open the result in Sonnet to check the structure looks right.
Check the structure in Sonnet
Open any JSON file as a collapsible tree to see its structure at a glance. Offline, no ads, no account. Free on Google Play, with an optional one-time Pro unlock for bigger files and search.