Common JSON Errors and How to Fix Them
JSON has a deliberately tiny specification, which means nearly every error comes from the same short list. Once you recognise them, most "invalid JSON" messages take seconds to fix.
Trailing commas
This is the most common error by a wide margin.
{ "name": "Ashraful", "role": "Engineer", }
That comma after the last value is invalid. JavaScript tolerates it, many languages tolerate it, JSON does not. Same rule inside arrays.
Single quotes
JSON requires double quotes, for both keys and string values. { 'name': 'Ashraful' } is not valid JSON even though it is perfectly good JavaScript. This trips people up constantly when copying an object out of code.
Unquoted keys
{ name: "Ashraful" } is a valid JavaScript object and invalid JSON. Every key must be a quoted string.
These last two points come from the same root confusion: JSON looks like JavaScript object syntax but is a stricter, separate format. Anything you copy out of code needs checking rather than assuming.
Comments
JSON has no comment syntax. Neither // nor /* */ is allowed. This is a frequent source of frustration in configuration files, and the usual workaround is a throwaway key such as "_comment".
Unescaped characters inside strings
Double quotes, backslashes, and literal line breaks inside a string must be escaped:
\"for a quote\\for a backslash\nfor a newline
Windows file paths are a classic offender, since C:\Users\file needs each backslash doubled.
Values JSON does not have
JSON supports strings, numbers, booleans, null, objects, and arrays. It does not support undefined, NaN, Infinity, dates, or functions.
Dates are the practical one: there is no date type, so dates are conventionally stored as ISO 8601 strings such as "2026-08-03T10:30:00Z".
Numbers with leading zeros or a trailing decimal point
007 and 3. are both invalid. Write 7 and 3.0. If leading zeros matter, such as a product code, it is a string, not a number.
Reading the error message
Most parsers report something like Unexpected token } at position 47. Two things are worth knowing.
First, the position is where the parser noticed the problem, which is often slightly after where you made it. A missing comma on one line is usually reported at the start of the next.
Second, "unexpected end of input" almost always means an unclosed bracket or brace. Formatting the document is the fastest way to find it, since proper indentation makes an unbalanced structure visible immediately.
A practical debugging order
- Format the JSON. Indentation alone reveals most structural problems.
- Scan for trailing commas, especially before
}and]. - Check quotes are double, on both keys and string values.
- Look for stray comments.
- Check escaping inside any string containing paths, quotes, or line breaks.
If a document is very large, cut it in half and validate each part. A few rounds of that narrows the problem quickly.
Try it yourself — free, and everything runs in your browser.
Open JSON Formatter & Validator