In this article
Why JSON is so strict
JSON looks like JavaScript, but its rules are much stricter so that every program in every language reads it the same way. Things JavaScript tolerates, trailing commas, single quotes, comments, are errors in JSON. The JSON Validator checks against the official standard (RFC 8259) and points to the line and column of the problem.
The usual suspects
| Mistake | Broken | Fixed |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'name': 'Ali'} | {"name": "Ali"} |
| Unquoted key | {name: "Ali"} | {"name": "Ali"} |
| Comment | {"a": 1 // note} | Remove the comment |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Unescaped quote in text | {"q": "He said "hi""} | {"q": "He said \"hi\""} |
| Special values | {"x": NaN, "y": undefined} | Use null or a number |
| Leading zero | {"code": 007} | {"code": "007"} (as text) |
Reading the error position
The error is usually at or just before the position reported. If the validator says “line 14, column 3”, look at the end of line 13 too, a missing comma there only becomes a problem when the next line starts. For a missing closing bracket, the error may appear at the very end of the file; count your opening and closing brackets in the formatted version.
Duplicate keys: the silent bug
JSON like {"price": 10, "price": 12} is accepted by many parsers, which quietly keep the last value. That can cause bugs that are very hard to track down, a config setting that “does not work” because it is overridden further down. The validator warns about duplicate keys that other tools ignore.
Copy-paste traps
- Curly quotes: word processors and chat apps change
"into “ and ”. JSON only accepts straight quotes. - Invisible characters: non-breaking spaces and byte-order marks from documents. Clean them with Remove Extra Spaces.
- Half a response: logs and consoles sometimes cut long output. If the error is “unexpected end”, check that you copied everything.
How to validate
- Paste your JSON into the JSON Validator.
- Read the result: valid, or an error with line and column.
- Fix and re-check. For valid JSON, the summary shows type, number of keys, nesting depth and size.
- Format it neatly with the JSON Formatter.
Config files that allow comments
Some tools use JSON-like formats that do allow comments or trailing commas, such as VS Code settings (JSONC) or JSON5. Those files are not strict JSON, so a strict validator will complain. If a tool’s documentation says comments are allowed, trust that tool; if the file is sent to an API, use strict JSON.
Private checking
Configuration files often contain passwords and keys. Validation happens in your browser, and nothing is uploaded.
Frequently asked questions
What does unexpected token mean in JSON?
The parser found a character where it did not expect one, often a missing comma or quote.
Are trailing commas allowed in JSON?
No. A comma after the last item in an object or list makes the JSON invalid.
Can JSON use single quotes?
No. JSON names and strings must use double quotes.
Can JSON contain comments?
Standard JSON does not allow comments. Remove them before parsing.
How do I find the error line?
A JSON validator shows the line and position of the first error.
What does “Unexpected token” mean in JSON?
The parser found a character it did not expect at that position, often a quote, comma or bracket in the wrong place. Look at the character just before the reported position.
Can JSON have trailing commas or comments?
No. Standard JSON allows neither. Remove the last comma in each list or object and delete any comments.
Why does my JSON fail because of quotes?
JSON only accepts double quotes around keys and text. Replace single quotes and curly “smart” quotes with straight double quotes.