JSON Basics: Syntax, Common Errors, and How to Fix Them
JSON (JavaScript Object Notation) is the most widely used format for exchanging data between servers, APIs, and applications. It's readable, lightweight, and supported natively by nearly every programming language. Here's what you need to know to write it correctly.
The building blocks
JSON has exactly six data types: strings, numbers, booleans (true/false), null, objects, and arrays. An object is a set of key-value pairs wrapped in curly braces; an array is an ordered list wrapped in square brackets.
{
"name": "Ada Lovelace",
"born": 1815,
"isProgrammer": true,
"languages": ["Analytical Engine notation"],
"employer": null
}
The five mistakes that break JSON
| Mistake | Wrong | Right |
|---|---|---|
| Trailing comma | {"a":1,} | {"a":1} |
| Unquoted keys | {a:1} | {"a":1} |
| Single quotes | {'a':'b'} | {"a":"b"} |
| Comments | {"a":1 // note} | Not allowed in JSON at all |
| Undefined / functions | {"a":undefined} | Use null instead |
Why validators give confusing error messages
Most JSON parsers stop at the exact character where the structure stops making sense — which is often after the actual mistake. If you get an error at line 4, check line 3 first; a missing comma or unclosed brace on an earlier line is the usual culprit.
Try it yourself
Paste your JSON into the JSON Formatter & Validator to get an instant, precise error location and a cleanly indented result.