JSON Parse Errors: Every Error Explained and Fixed
JSON parse errors are some of the most common errors in web development. Whether you are calling an API, reading a config file, or debugging a data pipeline, invalid JSON stops everything. This guide covers every common JSON syntax error with the exact fix for each one.
How to Read a JSON Parse Error
When JSON.parse() fails in JavaScript, the error message tells you where the problem is:
SyntaxError: Unexpected token } in JSON at position 47The position number is the character offset from the start of the string. Counting from zero by hand is painful. Paste the JSON into JSONKit's validator at /json-validator instead — it shows you the exact line number and column number and highlights the error in red.
Error 1: Trailing Comma
The most common JSON mistake. JavaScript allows trailing commas. JSON does not.
Bad:
{
"name": "Ravi",
"age": 28,
}Fixed:
{
"name": "Ravi",
"age": 28
}Remove the comma after the last property. The same rule applies to the last item in an array: `[1, 2, 3,]` is invalid JSON.
Error 2: Single Quotes
JavaScript objects use single quotes freely. JSON requires double quotes for every string — both keys and values.
Bad:
{'name': 'Ravi', 'city': 'Surat'}Fixed:
{"name": "Ravi", "city": "Surat"}Error 3: Unquoted Keys
JSON keys must always be strings wrapped in double quotes. JavaScript object syntax allows unquoted keys; JSON does not.
Bad:
{name: "Ravi", age: 28}Fixed:
{"name": "Ravi", "age": 28}Error 4: undefined, NaN, and Infinity
These are valid JavaScript values but are not part of the JSON specification. Use null instead.
Bad:
{"result": undefined, "ratio": NaN, "limit": Infinity}Fixed:
{"result": null, "ratio": null, "limit": null}Note: JSON.stringify() in JavaScript silently converts NaN and Infinity to null and drops undefined properties entirely.
Error 5: Comments
JSON does not support comments of any kind — no // single-line comments and no /* */ block comments.
Bad:
{
// database config
"host": "localhost",
"port": 5432 /* default postgres port */
}Fixed: remove all comments. If you need commented config files, use YAML instead — it supports # comments natively.
Error 6: Missing Comma Between Properties
Each property in a JSON object must be separated by a comma.
Bad:
{
"name": "Ravi"
"age": 28
}Fixed:
{
"name": "Ravi",
"age": 28
}The parser hits the unexpected `"` at the start of `"age"` and throws because it expected either `,` or `}`.
Error 7: Missing Closing Bracket or Brace
Every opening bracket `[` or brace `{` must have a matching closing bracket `]` or `}`.
Bad:
{"users": [{"name": "Ravi"}, {"name": "Priya"}Fixed:
{"users": [{"name": "Ravi"}, {"name": "Priya"}]}For large JSON files, use JSONKit's formatter — it will immediately show you where the brackets are unbalanced.
Error 8: Number as Key
JSON object keys must always be strings. A number as a key is invalid.
Bad:
{1: "one", 2: "two"}Fixed:
{"1": "one", "2": "two"}Error 9: Extra Data After the Root Value
JSON allows exactly one root value. Any text after the closing brace or bracket causes a parse error.
This commonly happens when an API response returns two JSON objects instead of wrapping them in an array:
Bad:
{"id": 1}{"id": 2}Fixed:
[{"id": 1}, {"id": 2}]Error 10: String with Unescaped Special Characters
Strings in JSON must not contain raw newlines, tabs, or backslashes — these must be escaped.
Bad:
{"path": "C:Users
avidocuments"}Fixed:
{"path": "C:\Users\ravi\documents"}Escape sequences in JSON: `\\` for backslash, `\n` for newline, `\t` for tab, `\"` for double quote.
How to Fix JSON Errors Fast
The fastest way to fix JSON errors is to paste your JSON into JSONKit's validator at /json-validator. It:
- Highlights the error with exact line and column numbers
- Explains what went wrong in plain English
- Updates live as you type — you see the error disappear the moment you fix it
- Shows a green success card with file size and line count once the JSON is valid
For programmatic validation in JavaScript or Python, wrap JSON.parse() or json.loads() in a try/catch block and log the error message.