JSON
Common JSON Errors: The Five Mistakes That Break Every Parse
Published 2026-08-15 · 8 min read
TL;DR: Most JSON parse failures come from a short list: trailing commas, unquoted or single-quoted keys, missing commas, stray comments and unbalanced braces - each reported by a validator with a line and column.
The error message is the problem: a parser tells you the parse failed, not why. Because the same handful of mistakes cause the overwhelming majority of failures, learning to recognize them by their error text is faster than reading the spec. This guide maps the common errors to their causes and fixes, using the JSON validator as the diagnostic. The grammar behind every check comes from the JSON specification.
Why does JSON fail with an unexpected } or ]?
Symptom: The parser reports an unexpected } or ]. Diagnostic: A trailing comma left the object or array expecting another value, or a brace is closed that was never opened. Fix: Remove the comma after the last element, then recheck the braces with a validator.
// invalid: trailing comma
{"a": 1,}
// valid
{"a": 1}Why does JSON fail with an unexpected token at a position?
Symptom: The parser reports a token where it expected a value or a comma. Diagnostic: One of three things: a missing comma between values, an unquoted key, or a single-quoted string. Fix: Find the position, add the comma or the double quotes, and validate again.
// invalid: missing comma
{"a": 1 "b": 2}
// invalid: single-quoted key
{'a': 1}
// valid
{"a": 1, "b": 2}Why does JSON fail with an unterminated string?
Symptom: The parser reaches the end of the document while inside a string. Diagnostic: A quote was opened and never closed, or a quote inside the value was not escaped. Fix: Close the string, or escape an internal quote as \".
// invalid: unescaped quote inside a string
{"note": "say "hi""}
// valid
{"note": "say \"hi\""}Why does JSON fail because a comment is not allowed?
Symptom: The parser rejects the document at a // or /*. Diagnostic: JSON has no comment syntax; the file is JSONC or a JavaScript object literal. Fix: Remove the comments, or use a parser that accepts JSONC if you control the reader.
// invalid as JSON
{"a": 1} // trailing commentWhy does JSON fail with non-whitespace after the document?
Symptom: The document parses, then the parser finds more content. Diagnostic: Two documents were concatenated, or a trailing comma was followed by nothing. Fix: Wrap multiple documents in an array, or remove the trailing characters.
// invalid: two documents
{"a": 1}
{"b": 2}
// valid: one array
[{"a": 1}, {"b": 2}]How do you track down an error in a huge file?
The validator reports the line and column, so the workflow is: paste the file, read the location, jump to it, fix the one token. If the error message names a position but the fix is not obvious, format the document first - the JSON formatter makes the surrounding structure visible, and the error usually becomes obvious once the nesting is indented.
What tools catch JSON errors for you?
A validator is faster than reading by eye, and it names the exact line and column. A good one does two passes: it checks that the grammar is legal, then it checks that the result matches what you expect. The first pass catches syntax errors; the second catches a valid document that is still wrong, such as a missing key or an array in place of an object.
- A formatter that does not crash is a weak validator: minify then reformat, and compare the result.
- A diff tool shows the change that broke a previously working file.
- A schema validator checks shape, not just grammar.
Rule of thumb: the parser is never wrong about the grammar. When a file was working and then stopped, the difference is always a real byte change - compare the old and new versions instead of assuming a parser bug.
How do you check a whole file in one pass?
- Paste the document into the JSON validator.
- Read the reported line and column.
- Fix the offending token.
- Validate again until it passes.
A document that passes the validator is syntactically correct. It still needs to match your application's expected shape - that is schema validation, a separate step. Add schema checks such as JSON Schema when the document must satisfy business rules like a required key, a bounded value or a fixed date format, because syntax alone cannot catch those.
Related Tools
Related Guides
How to Validate JSON: Find the Exact Line and Column of a Syntax Error
Validate JSON syntax with the online validator, JSON.parse in JavaScript or json.loads in Python, and diagnose the most common parse errors.
JSON Syntax Guide: The Six Value Types and the Rules That Catch You
A complete walkthrough of JSON syntax: objects, arrays, strings, numbers, booleans and null, plus the edge cases that break real documents.
How to Format JSON: Readable Output in the Browser, Editor or Terminal
Format minified JSON for readability with an online formatter, an editor shortcut, or a command-line tool like jq or python -m json.tool.
Frequently Asked Questions
Why does my browser accept JSON that the validator rejects?
Browsers and editors often use tolerant parsers that allow trailing commas, comments and single quotes. The validator is strict, so it catches the difference before a strict backend does.
What is the fastest way to find a missing comma?
Format the document first; the broken nesting makes the gap visible. Then let the validator confirm the exact line.
Are JSON errors the same in every language?
The grammar is the same, so the causes are the same, but messages differ. Python reports a line and column, JavaScript reports a character position, Go reports a byte offset. The cause behind the message is the same short list.
Why does the validator pass but my API reject the file?
The API is probably validating a schema, not just syntax. A syntactically valid document can still be missing required keys or have the wrong value types.