Understanding JSON Syntax
JSON (JavaScript Object Notation) has a deceptively simple grammar, but a handful of strict rules trip up even experienced developers. Every string (including object keys) must be wrapped in double quotes. Single quotes and unquoted identifiers, which JavaScript happily accepts, are illegal in JSON. Trailing commas after the last element of an array or object are also forbidden; most linting errors originate from this single mistake.
JSON supports exactly six data types: string, number (no distinction between integer and float), boolean (true/false), null, object, and array. Notably absent are undefined, Date, RegExp, and functions, all of which must be serialized to strings or numbers before encoding. Comments are not part of the specification either; if you need annotated config files, consider JSONC or JSON5.
While the spec imposes no nesting depth limit, most parsers and APIs cap recursion at 100-512 levels. Deeply nested structures also hurt readability and performance, so flatten your data model when nesting exceeds three or four levels. Use our JSON Validator to catch these issues instantly.