Lesson 5
Common JSON Errors
Trailing commas, comments, single quotes, and other frequent mistakes.
Invalid JSON usually fails fast at parse time. Recognizing these patterns saves time when debugging API integrations or config files.
Trailing commas
{
"a": 1,
"b": 2,
}
JavaScript allows the comma after 2; JSON does not. Remove commas before } or ].
Single quotes
{ 'name': 'Ada' }
JSON strings must use double quotes ".
Unquoted keys
{ name: "Ada" }
Keys are strings and require double quotes: { "name": "Ada" }.
Comments
// not allowed in JSON
{ "x": 1 }
Use README files or JSON Schema descriptions for documentation—not inline comments.
Invalid literals
True/False— must be lowercasetrue/falseundefined— omit the property or usenullNaN,Infinity— not valid JSON numbers
Smart quotes and invisible characters
Copying from Word or web pages may insert " " instead of ". Editors may add BOM or non-breaking spaces. If parsing fails with a cryptic position error, re-type quotes or paste through a plain-text editor.
Almost-JSON from JavaScript
When developers log objects or copy from browser consoles, output may look like JSON but include functions, undefined, or unquoted keys. Always run through a strict parser before treating text as JSON.
Fixing workflow
- Read the parser error line and column.
- Check the line above closing brackets for extra commas.
- Verify all strings and keys use
". - Remove comments and JavaScript-only syntax.
These rules are strict by design—strictness is what makes JSON portable across systems.