In this article
JSON (JavaScript Object Notation) is the language of APIs, config files and app data. It’s simple — but strict. One misplaced comma and the whole thing fails with a cryptic message like “Unexpected token } in JSON at position 42”. Here are the seven mistakes behind most of those errors.
1. Trailing commas
{
"name": "Toolsopedia",
"tools": 72,
}
The comma after 72 has nothing after it. JavaScript tolerates this; JSON doesn’t.
Fix: remove the comma after the last item in every object {} and array [].
2. Single quotes
{ 'name': 'Toolsopedia' }
Fix: JSON requires double quotes for both keys and string values: { "name": "Toolsopedia" }.
3. Unquoted keys
{ name: "Toolsopedia" }
Fix: every key must be a double-quoted string: { "name": "Toolsopedia" }.
4. Comments
{
// number of tools
"tools": 72
}
Fix: remove comments. If you need notes, add them as data: "_note": "number of tools".
5. Missing commas or brackets
{
"name": "Toolsopedia"
"tools": 72
}
A missing comma between items, or an unclosed { or [, is the most common error in hand-edited files.
Fix: format the JSON with indentation — mismatched brackets and missing commas become obvious when every item sits on its own line.
The line and column in an error message show where the parser gave up, which is often just after the real mistake. Look at the end of the previous line first.
6. Invalid values
JSON supports only these value types: string, number, true, false, null, object and array. These are not allowed:
| Invalid | Use instead |
|---|---|
undefined | null or omit the key |
NaN, Infinity | null or a string |
True, FALSE | true, false (lowercase) |
0123 (leading zero) | 123 or "0123" as a string |
.5 | 0.5 |
7. Unescaped characters in strings
Quotes, backslashes and line breaks inside a string must be escaped:
{ "path": "C:\new\folder", "quote": "She said "hi"" }
Fix:
{ "path": "C:\\new\\folder", "quote": "She said \"hi\"" }
Line breaks inside strings must be written as \n.
Debugging checklist
- Paste the JSON into a formatter and read the error’s line and column.
- Check the line before the reported position.
- Look for trailing commas, single quotes, missing commas and comments.
- Format with indentation to see the structure clearly.
- Validate again until it parses.
Bonus: format vs minify
- Formatted (pretty-printed) JSON is easy for humans to read and debug.
- Minified JSON removes whitespace to make files smaller for sending over networks.
Both contain exactly the same data.
Validate privately
Our JSON Formatter beautifies, minifies, sorts keys and validates JSON — showing the error with its line and column. It runs in your browser, so API responses with tokens or personal data are never sent anywhere.
Free toolTry the JSON FormatterBeautify, validate or minify JSON with clear error messages.Frequently asked questions
Why does my JSON work in JavaScript but fail in JSON.parse?
JavaScript object literals allow single quotes, unquoted keys, trailing commas and comments. JSON doesn't. Paste it into a validator to find the differences.
Can JSON have comments?
Standard JSON can't. Some tools accept variants like JSONC or JSON5 for config files, but APIs expect strict JSON.
What's the difference between null and an empty string?
null means 'no value'; "" is a string with zero characters. Both are valid JSON, but APIs may treat them differently.
Written by the Toolsopedia team. Spotted an error? Tell us and we’ll fix it.