Common JSON Errors and How to Fix Them
Updated September 30, 2026 · 8 min read
JSON is strict. A single stray comma or quote makes the whole document invalid, and the parser's error message is often cryptic. This guide walks through the errors you will meet most often, what causes each one, and how to fix it. To follow along, paste your own JSON into the JSON validator, which shows the error and its position.
How to read a JSON error message
Every engine words its errors differently. Chrome and Node.js say things like Expected double-quoted property name in JSON at position 25, Firefox says JSON.parse: expected double-quoted property name at line 3 column 1, and Safari says JSON Parse error: Unexpected identifier. The wording differs, but the pattern is the same: the parser stops at the first character it cannot accept. The real mistake is usually at that position or just before it, often on the previous line. Fix one error at a time and re-validate, because later errors are hidden until earlier ones are gone.
1. Trailing comma
A comma after the last item is fine in JavaScript, but not in JSON.
{
"name": "Ada",
"role": "admin",
}
The parser reads the comma, expects another key, and finds } instead. Typical messages: Expected double-quoted property name or Unexpected token }. Fix: delete the comma after the last property or array item. The same applies to arrays such as [1, 2, 3,].
2. Single quotes instead of double quotes
{ 'name': 'Ada' }
JSON only allows double quotes, for both keys and string values. Typical messages: Unexpected token ', or Expected property name. Fix: replace every single-quoted string with a double-quoted one. If the text contains a double quote, escape it as \".
3. Unquoted keys
{ name: "Ada" }
This is valid JavaScript but not JSON. Every key must be a double-quoted string. Fix: write { "name": "Ada" }.
4. Comments
{
// the user
"name": "Ada" /* required */
}
JSON has no comment syntax. The parser fails at the first /. Fix: remove the comments. If you need notes in configuration, use a format that supports comments, such as YAML (see JSON to YAML), or add a dedicated key like "_comment" that your program ignores.
5. Missing comma or bracket
{
"a": 1
"b": 2
}
Without a comma between properties, the parser fails on the second key: Expected ',' or '}' after property value. A missing closing brace or bracket gives Unexpected end of JSON input (Chrome) or unexpected end of data (Firefox), because the text stops while the parser is still waiting for more. Fix: add the comma, or count your opening and closing { } and [ ]. Consistent indentation makes a missing closer easy to spot, which is why JSON Prettier is useful once the document parses.
6. Unexpected end of JSON input (empty or truncated data)
This exact message also appears when you parse an empty string, for example when an API returns an empty body or a file failed to load. Check that the text is not empty and was not cut off, for instance by a size limit, a failed download, or a copy that missed the last line.
7. Unexpected token < in JSON at position 0
The text starts with <, which means you received HTML, not JSON. Common causes are a 404 or 500 error page, a login redirect, or a wrong URL. Fix: open the URL in a browser, check the status code and the Content-Type header, and confirm the endpoint really returns JSON.
8. Invalid values: undefined, NaN, Infinity, and Python constants
{ "a": undefined, "b": NaN, "c": True, "d": None }
JSON's only literals are true, false, and null. undefined, NaN, and Infinity come from JavaScript, and True, False, and None from Python. A message like Unexpected token 'u', "undefined" is not valid JSON is typical. Fix: use null (or omit the key) and lowercase true and false. When generating JSON, use a real serializer such as JSON.stringify or Python's json.dumps rather than string concatenation.
9. Unescaped characters inside strings
{ "path": "C:\new\folder", "note": "line one
line two" }
Inside a string, a backslash begins an escape sequence, and raw line breaks and tabs are not allowed. Bad control character in string literal and Unterminated string are typical messages. Fix: escape backslashes as \\, and write line breaks and tabs as \n and \t, giving "C:\\new\\folder" and "line one\nline two". A literal double quote inside a string must be written \".
10. Numbers JSON does not accept
Numbers cannot have leading zeros (007), a leading plus sign (+5), a trailing or leading decimal point (5., .5), or hexadecimal notation (0xFF). Fix: write 7, 5, 5.0 or 0.5, and 255. If a leading zero matters, such as a ZIP code, store the value as a string.
11. A byte order mark or stray characters at the start
Files saved by some editors begin with an invisible byte order mark (BOM), which can cause an error at position 0. Copying text from a web page or chat can also add non-breaking spaces or "smart" curly quotes (“ ”), which are not valid JSON quotes. Fix: re-save as UTF-8 without a BOM, and retype any curly quotes as straight quotes.
Fix many of these automatically
The JSON Prettier page has a Repair JSON button that appears when JSON is invalid. It removes comments and trailing commas, quotes bare keys, converts single quotes, and replaces Python and JavaScript constants. It cannot fix missing brackets, truncated data, or unescaped characters, and it leaves your text unchanged if the result is still invalid. For those, use the line and column shown by the validator.
A quick checklist
- Is the text non-empty and complete? Does it start with
{or[? - Are all keys and strings in double quotes?
- Is there exactly one comma between items, and none after the last one?
- Do all
{ }and[ ]pairs match? - Are values limited to strings, numbers, objects, arrays,
true,false, andnull? - Are backslashes, quotes, line breaks, and tabs inside strings escaped?
Related tools
- JSON Validator: find the exact error position.
- JSON Prettier: pretty print and repair invalid JSON.
- JSON Diff: see what changed between two versions.
- Format JSON: the full formatter, viewer and converter.