A single missing comma can stop an application from loading its config. JSON's grammar, defined in RFC 8259 and ECMA-404, allows none of the shortcuts JavaScript and Python accept. Below are the seven JSON errors I see most, the exact message each produces, and the fix.
What are the most common JSON formatting errors?
The seven most common JSON errors are trailing commas, single or curly quotes, unquoted keys, missing commas, unclosed or mismatched brackets, unescaped backslashes or line breaks inside strings, and values JSON doesn't have, such as comments, NaN, undefined and Python's True. Any one of them makes the whole document fail to parse. The error message points at the character where the parser gave up, which is often just after the real mistake.
JSON errors and their messages at a glance
Each row shows a broken input and its message in Chrome, Edge and Node.js, which share the V8 engine (output from Node.js 24), and in Python 3.13's json module. Firefox words its messages differently; MDN lists them on its JSON.parse: bad parsing page.
| Mistake | Input | Chrome and Node.js | Python 3.13 |
|---|---|---|---|
| Trailing comma | {"name": "Ada", "age": 36,} | Expected double-quoted property name in JSON at position 26 (line 1 column 27) | Illegal trailing comma before end of object: line 1 column 26 (char 25) |
| Single quotes or unquoted key | {'name': 'Ada'} or {name: "Ada"} | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
| Missing comma | {"name": "Ada" "age": 36} | Expected ',' or '}' after property value in JSON at position 15 (line 1 column 16) | Expecting ',' delimiter: line 1 column 16 (char 15) |
| Mismatched bracket | {"name": "Ada", "tags": ["x", "y"} | Expected ',' or ']' after array element in JSON at position 33 (line 1 column 34) | Expecting ',' delimiter: line 1 column 34 (char 33) |
| Bad escape | {"path": "C:\Users\ada"} | Bad escaped character in JSON at position 13 (line 1 column 14) | Invalid \escape: line 1 column 13 (char 12) |
| Non-JSON value | {"active": True} | Unexpected token 'T', "{"active": True}" is not valid JSON | Expecting value: line 1 column 12 (char 11) |
1. Trailing commas
In many programming languages, JavaScript and PHP among them, a trailing comma after the last array item is fine. In JSON it is a fatal error, because the grammar expects another value after every comma. It usually appears when you delete the last line of a list. Arrays fail the same way:
[1, 2, 3,]
Chrome/Node.js: Unexpected token ']', "[1, 2, 3,]" is not valid JSON
Python 3.13: Illegal trailing comma before end of array: line 1 column 9 (char 8)
The fix is to delete the comma after the last item. I always run a JSON validator before deploying, because a stray comma is easy to miss in code review.
2. Single quotes and curly quotes
I often see developers use single quotes (') in JSON objects. JSON requires double quotes (") around every key and every string value; RFC 8259 says a string "begins and ends with quotation marks". A single-quoted value fails with Unexpected token ''', "{"name": 'Ada'}" is not valid JSON in Chrome. Curly quotes (“ ”) pasted from Word or Google Docs produce the same messages as single quotes and are harder to spot, so search for them and replace them with straight double quotes. In a code editor or our regex tester, the pattern [“”‘’] finds all four curly quote characters at once.
3. Unquoted property names
{name: "Ada"} is a valid JavaScript object literal but not valid JSON, and it usually arrives by copying console output: Node.js prints an object as { name: 'Ada', age: 36 }, which breaks two rules at once. If the data is already in a JavaScript program, let JSON.stringify({name: "Ada", age: 36}) write it; that returns {"name":"Ada","age":36}.
4. Missing commas between items
A missing comma usually happens when you add a line to the end of an object. The reported position is the start of the next item ("age" in the table above), so the comma belongs just before it, which in formatted JSON means the end of the previous line.
5. Unclosed or mismatched brackets
When an array is closed with } instead of ], the parser reports the position of the wrong bracket: column 34 in the example is the }. A document that was cut off, such as half an API response copied from a terminal, fails at its last character: {"name": "Ada" gives Expected ',' or '}' after property value in JSON at position 14. Indentation makes it easy to see which bracket closes which block.
6. Backslashes and line breaks inside strings
RFC 8259 requires three kinds of characters to be escaped inside a string: the double quote, the backslash and control characters (U+0000 to U+001F, which include the tab and the line break). The only valid escapes are \", \\, \/, \b, \f, \n, \r, \t and \uXXXX. A Windows path breaks because \U isn't one of them; write "C:\\Users\\ada" instead. A real line break inside a string fails too:
{"note": "line one
line two"}
Chrome/Node.js: Bad control character in string literal in JSON at position 18 (line 1 column 19)
Python 3.13: Invalid control character at: line 1 column 19 (char 18)
Replace the line break with \n.
7. Comments, NaN and other values JSON doesn't have
JSON has exactly three literal names, true, false and null, all lowercase. It has no comments, no undefined, and RFC 8259 says numbers such as NaN and Infinity "are not permitted". Leading zeros aren't allowed either, so {"zip": 02134} fails with Unexpected number in JSON at position 9; store ZIP codes and phone numbers as strings. Watch for this when JSON comes out of a converter: our CSV to JSON converter turns number-like cells into numbers, so 02134 becomes 2134 (valid JSON, wrong ZIP code), and you need to put the quotes and the zero back in the output yourself. A // comment fails with the missing-comma message, because the parser expected a comma or closing brace where the comment starts.
Python has a twist here. Its json module reads NaN without complaint, and json.dumps({"score": float("nan")}) writes {"score": NaN}, a default the Python documentation calls "not JSON specification compliant". A browser then rejects the file with Unexpected token 'N'. Pass allow_nan=False to catch it in Python. JavaScript goes the other way: JSON.stringify({a: NaN, b: undefined, c: Infinity}) quietly returns {"a":null,"c":null}.
JSON parse errors that aren't typos
Some JSON errors have nothing to do with a comma. The text you are parsing is empty, cut short, or isn't JSON at all. These come from Node.js 24, and Chrome shows the same wording.
Unexpected end of JSON input
The parser reached the end before the value was finished. JSON.parse("") throws exactly this, and so does response.json() in a fetch call when the server sends an empty body, as every 204 No Content response does. Check the status code before you parse, and log the raw text with response.text() when parsing fails.
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
The response is an HTML page. A 404 page, a login redirect or a server error page starts with <, and the parser stops there. The JSON itself is fine; the request went to the wrong place or was refused. Open the request in the Network tab of DevTools and read the response body.
Unexpected non-whitespace character after JSON
The parser read one complete value and found more text after it. Two objects on separate lines ({"a":1} then {"b":2}) give at position 8 (line 2 column 1), and Python calls the same problem Extra data. If the file holds one object per line, it's JSON Lines and needs to be read line by line.
A byte order mark at the start
Files saved by some Windows editors begin with an invisible byte order mark (U+FEFF). JSON.parse rejects it with Unexpected token followed by the invisible character, and Python says Unexpected UTF-8 BOM (decode using utf-8-sig). Open the file with encoding="utf-8-sig" in Python. Our formatter trims whitespace before it parses, and JavaScript's trim counts the BOM as whitespace, so pasted text with a BOM formats without the error.
How to find the error position quickly
- Paste the JSON into our JSON formatter and click Validate. Invalid input shows
✕ Invalid JSON:followed by your browser's parser message, the same text as in the table above. - Read the position. "Position 26" counts characters from 0, and "line 1 column 27" is the same spot counted from 1. The tool trims whitespace from both ends before parsing, so the count starts at the first real character.
- Look just before that spot. For missing and trailing commas, the mistake is usually the character before the reported position.
- Fix one error at a time, because the parser only reports the first. Once the JSON parses, Format / Prettify (or Ctrl+Enter) indents it.
The formatter runs in your browser, so you can check JSON errors in config files that hold keys or tokens without the file leaving your machine. JSON formatter vs validator explains how the two jobs differ, and what is JSON covers the basic syntax.
How to fix JSON errors: a checklist
- Read the first error only, and look at the character just before the reported position.
- If the message mentions
<or "end of JSON input", check what the server returned before editing anything. - Search for curly quotes, single quotes and a comma before every
}or]. - Replace
True,False,None,NaNandundefinedwithtrue,false,nullor a number. - Double every backslash in Windows paths and turn real line breaks inside strings into
\n. - Validate again, and repeat until the status reads
✓ Valid JSON. If an edit broke JSON that used to parse, compare both versions in the Diff Checker.
How to format JSON in your browser covers pasted inputs that look like JSON but won't format, such as escaped strings and JSON Lines.
Frequently asked questions
Why does the error point to the wrong place?
The parser reports where it stopped, not where you went wrong. With a missing comma, the text is fine until the next key starts, so that's where the position lands; with a missing closing bracket, it may read to the end of the document first. Check the line before the reported position.
Can I make JSON accept comments and trailing commas?
Not standard JSON. RFC 8259 lets a parser accept extensions, and JSON5 allows comments, trailing commas, single-quoted strings and unquoted keys. But JSON.parse and Python's json module reject that syntax, so use JSON5 only for files your own tooling reads, and send plain JSON to anything else.