Glossary · Definition
JSON syntax rules
JSON syntax: 6 value types (string, number, true, false, null, object, array). Strings use double quotes ONLY. Object keys must be quoted strings. No trailing commas, no comments, no single quotes. Common errors: missing commas, unquoted keys, trailing commas after last item.
Definition
JSON syntax: 6 value types (string, number, true, false, null, object, array). Strings use double quotes ONLY. Object keys must be quoted strings. No trailing commas, no comments, no single quotes. Common errors: missing commas, unquoted keys, trailing commas after last item.
What it means
RFC 8259 specifies six allowed value types and their syntax. <strong>Strings</strong>: double-quoted only (no single quotes), with backslash escapes for special chars (<code>\"</code>, <code>\\</code>, <code>\n</code>, <code>\t</code>, <code>\u0041</code>). <strong>Numbers</strong>: integers and floats (no leading zeros, no octal/hex, no NaN, no Infinity). <strong>Boolean</strong>: only <code>true</code> and <code>false</code> (lowercase). <strong>Null</strong>: <code>null</code> (lowercase). <strong>Objects</strong>: <code>{key: value, ...}</code> with quoted string keys, comma-separated, no trailing comma. <strong>Arrays</strong>: <code>[value, value, ...]</code> with elements comma-separated, no trailing comma. <strong>Nesting</strong>: arbitrary depth (some parsers limit to 100-1000 levels).
Advertisement
Why it matters
Most JSON parse errors come from these specific rules. Knowing them speeds debugging dramatically. JavaScript developers especially trip over JSON’s strictness — JS allows trailing commas, single quotes, unquoted keys; JSON doesn’t. Copy-paste from JavaScript object literals into a JSON file usually breaks. Common error message: <code>SyntaxError: Unexpected token X at position N</code> — N is the character position; look for the most common errors first.
Example
VALID: <code>{"name": "ada", "skills": ["js", "python"]}</code>. INVALID: <code>{name: ‘ada’, "skills": ["js", "python",]}</code> (unquoted key, single quotes, trailing comma).
Related free tools
Frequently asked questions
Can JSON have comments?
No — strict JSON forbids comments. Use JSON5 or JSONC if you need them. For pure JSON config files, document via README or external schema instead.
What’s the maximum nesting depth?
RFC doesn’t specify; parsers vary. JavaScript JSON.parse handles 1000-2000 levels; some embedded parsers cap at 100. Avoid deeply nested JSON in production — flatten or use references.
Why are trailing commas not allowed?
Historical: JSON was designed in 2001 when many parsers didn’t handle them. Modern parsers can handle them but the standard remained strict. JSON5 / JSONC removed this restriction.
Related terms
- DefinitionJSON vs JSON5JSON (RFC 8259) is the strict standard: keys must use double quotes, no comments, no trailing commas. JSON5 is a developer-friendly superset: allows unquoted keys, single quotes, comments, and trailing commas. Use JSON for APIs and data interchange; JSON5 for config files where humans edit.
- DefinitionJSON SchemaJSON Schema is a vocabulary for describing the structure of valid JSON: required fields, types, allowed values, nested-object shape. Use it for API request validation, OpenAPI docs, and structured data validation. Modern alternatives: TypeScript types (for compile time), Zod / Yup / Valibot (for runtime validation in JS).