JSON supports exactly six basic data types. Any valid JSON document must consist of these types nested within an object or an array.
The 6 Primitive Data Types
- String: Sequence of Unicode characters wrapped strictly in double quotes (
"hello"). Single quotes are invalid! - Number: Integer or floating-point numbers (e.g.
42,-3.14,1.2e5). Hexadecimal (0x1F) and leading zeroes (007) are forbidden. - Boolean: Either literal
trueorfalsein lowercase. - Null: Literal
nullrepresenting an empty or non-existent value. - Object: An unordered collection of key/value pairs enclosed in braces
{}. Keys must be double-quoted strings. - Array: An ordered sequence of values enclosed in square brackets
[].
Common JSON Syntax Pitfalls
- Trailing Commas: JSON forbids trailing commas in arrays or objects:
{"a": 1,}is invalid. - Single Quotes:
{'name': 'Alex'}causes a parse error; double quotes are required. - Comments: Standard JSON does not support comments (
//or/* */).