JSON Syntax and Structure
JSON has a small, strict grammar — curly braces for objects, square brackets for arrays, and a handful of rules about quoting and punctuation that must be followed exactly.
The Rules
Unlike JavaScript, JSON has no tolerance for shortcuts. Every rule below is strictly enforced by any conforming JSON parser.
- Objects are wrapped in curly braces
{ }, containing comma-separated key:value pairs. - Arrays are wrapped in square brackets
[ ], containing comma-separated values. - Keys must always be strings, wrapped in double quotes — never single quotes, never unquoted.
- No trailing commas are allowed after the last item in an object or array.
- No comments are allowed anywhere in a JSON document.
Valid vs Invalid JSON
Small mistakes that JavaScript would happily overlook will cause a JSON parser to reject the entire document.
{
"title": "Learn JSON",
"published": true,
"tags": ["data", "web", "api"]
}
Common Mistakes
- Using single quotes for strings or keys — JSON requires double quotes exclusively.
- Leaving a trailing comma after the last element in an array or object, which many parsers will reject.
- Adding comments (// or /* */) anywhere in the document — plain JSON has no comment syntax.
- Forgetting to close every opened brace or bracket, especially in deeply nested structures.
Professional Tip
When debugging invalid JSON, check the three most common culprits first: a trailing comma, single quotes instead of double quotes, or a missing closing brace/bracket. These three cover the vast majority of "why won't this parse" problems.
Your Turn
Take a JSON document with three intentional mistakes (a trailing comma, single quotes, and a missing bracket) and correct each one.
Mini Quiz
Which of the following is valid in standard JSON?