How to Fix Common JSON Errors: Unexpected Token, Trailing Comma & More
"Unexpected token" and "Unexpected end of JSON input" are two of the most common errors developers hit while working with JSON — and both usually come down to one of a handful of tiny syntax mistakes. Here's how to spot and fix each one.
Why JSON parsing is so strict
Unlike JavaScript object literals, JSON has no tolerance for shortcuts. There are no trailing commas, no unquoted keys, no single-quoted strings, and no comments. JSON.parse() throws the instant it hits something outside the spec, and the error message tells you roughly where — but not always why. The fixes below cover the errors you'll run into most.
1. Trailing comma after the last item
The most common mistake of all. A comma left after the final property or array item is invalid JSON, even though it's fine in JavaScript.
// Invalid — trailing comma after "active": true
{
"name": "Ada",
"active": true,
}
// Valid
{
"name": "Ada",
"active": true
}2. Unquoted or single-quoted keys
JSON keys must be wrapped in double quotes — not single quotes, and not left bare like a JavaScript identifier.
// Invalid
{ name: "Ada", 'role': "developer" }
// Valid
{ "name": "Ada", "role": "developer" }3. Unclosed brackets or braces
A missing closing } or ] usually produces "Unexpected end of JSON input" — the parser ran out of text before every bracket it opened was closed. Count your opening and closing brackets, especially in deeply nested objects.
// Invalid — missing closing brace for "address"
{
"name": "Ada",
"address": { "city": "London"
}
// Valid
{
"name": "Ada",
"address": { "city": "London" }
}4. "Unexpected token" at a specific character
This is the parser's way of saying "I found a character here that doesn't belong." The most frequent causes are a stray comma, a missing comma between two properties, or a value that isn't valid JSON (like undefined or a bare word).
// Invalid — missing comma between properties
{
"name": "Ada"
"role": "developer"
}
// Invalid — undefined is not valid JSON
{ "middleName": undefined }
// Valid
{
"name": "Ada",
"role": "developer",
"middleName": null
}5. Comments
JSON has no comment syntax at all — neither // nor /* */ is allowed, and including one will fail parsing every time, even if every other character is valid.
// Invalid — JSON doesn't support comments
{
// this is the user's name
"name": "Ada"
}The fastest way to find the mistake
Rather than scanning line by line, paste the JSON into a formatter that surfaces the exact parse error. Our JSON Formatter & Validator highlights exactly where parsing failed as soon as you paste, so you can jump straight to the offending character instead of guessing.
Paste your broken JSON to see exactly where it fails, then beautify or minify the fixed version.
Open JSON Formatter →