Common JSON Errors and How to Fix Them
A field guide to the most frequent JSON syntax errors, trailing commas, bad quotes, unbalanced brackets, and more, with clear fixes for each.
Almost every JSON parsing error traces back to one of a small set of recurring mistakes. Once you can recognize them on sight, debugging broken JSON goes from a slow line-by-line hunt to a quick pattern match. This guide walks through the most common errors, what the parser error message typically looks like, and exactly how to fix each one.
1. Trailing Commas
The mistake:
{
"name": "Utilir",
"version": 1,
}
Why it fails: JavaScript object and array literals allow a trailing comma after the last item, many developers type JSON the same way out of habit. JSON does not allow this. A comma must appear between elements, never after the last one.
Typical error: Something like Unexpected token } in JSON at position 41, pointing at or near the closing brace.
The fix: Remove the comma after the final property or array element:
{
"name": "Utilir",
"version": 1
}
2. Single Quotes Instead of Double Quotes
The mistake:
{
'name': 'Utilir'
}
Why it fails: JSON strings and keys must use double quotes exclusively. Single quotes are valid in JavaScript and Python but not in the JSON specification.
Typical error: Unexpected token ' in JSON at position 2, often reported right at the opening quote.
The fix: Replace every single quote used for a string or key with a double quote:
{
"name": "Utilir"
}
3. Unquoted Object Keys
The mistake:
{
name: "Utilir"
}
Why it fails: This is valid JavaScript (object keys can be bare identifiers) but invalid JSON, every key must be a double-quoted string, with no exceptions.
Typical error: Often reported as Unexpected token n in JSON at position 2, pointing at the start of the unquoted key.
The fix: Wrap every key in double quotes:
{
"name": "Utilir"
}
4. Unescaped Characters Inside Strings
The mistake:
{
"quote": "She said "hello" to me"
}
Why it fails: A literal double quote inside a JSON string must be escaped with a backslash (\"), because an unescaped one ends the string early, the parser sees "She said " as a complete string, then gets confused by what follows.
The fix: Escape internal quotes, or better, use a JSON serializer in your programming language rather than hand-building the string, since serializers handle escaping automatically:
{
"quote": "She said \"hello\" to me"
}
The same applies to literal backslashes (\\), newlines (\n), and a handful of other control characters, any of these appearing unescaped inside a string will break parsing.
5. Smart Quotes From Word Processors or Chat Apps
The mistake: JSON that looks correct visually but fails to parse, often after being copy-pasted from a Word document, a note-taking app, or a chat client with "smart typography" enabled:
{
“name”: “Utilir”
}
Why it fails: Those curly quotation marks (“ ”) are different Unicode characters from the straight double quote (") that JSON requires. They look nearly identical in many fonts, which makes this error especially frustrating to spot by eye.
The fix: Retype the quotes manually, or paste into a plain-text editor first to strip any "smart" formatting before copying into a JSON tool.
6. Unbalanced Brackets or Braces
The mistake:
{
"items": ["a", "b", "c"
}
Why it fails: Every [ needs a matching ], and every { needs a matching }. This example is missing the closing ] for the array.
Typical error: Often reported as Unexpected end of JSON input, since the parser reaches the end of the text still expecting more closing brackets.
The fix: Count opening and closing brackets carefully, especially in deeply nested structures. A formatter tool that indents consistently makes mismatched brackets far easier to spot visually than a single unbroken line does.
7. Trailing or Leading Non-JSON Text
The mistake: JSON copied from a log line or terminal output that includes extra text before or after the actual JSON, such as:
Response body: {"status":"ok"}
Why it fails: The parser expects the entire input to be a single valid JSON value. Any extra text, even something as small as a log prefix, makes the whole thing invalid.
The fix: Trim the input down to exactly the JSON portion, starting at the first { or [ and ending at the matching final } or ].
8. JavaScript-Only Values
The mistake:
{
"count": undefined,
"ratio": NaN
}
Why it fails: undefined, NaN, and Infinity are valid in JavaScript but have no representation in JSON. JSON's number type does not support these special values, and there is no equivalent to undefined at all, the closest valid representation is null.
The fix: Replace undefined with null, and reconsider whether NaN/Infinity values need a different representation (such as a string, or omitting the field entirely) for your use case.
9. Numbers With Leading Zeros or Trailing Dots
The mistake:
{
"id": 007,
"price": 12.
}
Why it fails: JSON numbers cannot have leading zeros (except for the number 0 itself) and cannot end with a bare decimal point with nothing after it.
The fix: Remove the leading zero (7 instead of 007, using a string "007" if the leading zero is meaningful, like a product code) and complete the decimal (12.0 or just 12).
A Faster Way to Find These
Reading through JSON by eye to spot one of these nine patterns works, but it's slow for anything beyond a few lines. Our JSON Validator parses your input and reports the exact line and column where parsing failed, along with plain-language hints pointing at the most likely cause, so instead of scanning the whole document, you can jump straight to the problem. Once your JSON validates, run it through our JSON Formatter to catch any remaining structural issues visually and produce a clean, readable copy.