JSON Syntax & Data Types
JSON has a simple syntax with just a few rules and six data types.
JSON Data Types
JSON supports exactly six data types:
- String - Text in double quotes:
"hello" - Number - Integer or decimal:
42,3.14 - Boolean -
trueorfalse - Null - Empty value:
null - Array - Ordered list:
[1, 2, 3] - Object - Key-value pairs:
{"key": "value"}
Syntax Rules
- Strings must use double quotes (not single quotes)
- Keys in objects must be strings with double quotes
- No trailing commas allowed
- No comments allowed in JSON
- Numbers cannot have leading zeros
Valid vs Invalid JSON
Common Mistakes
// INVALID: single quotes
{'name': 'Alice'}
// INVALID: trailing comma
{"name": "Alice",}
// INVALID: unquoted keys
{name: "Alice"}
// INVALID: comments
{"name": "Alice"} // user name
Exercise: Identify Data Types
Exercise: Fix Invalid JSON
Key Points
- JSON has only 6 data types
- Always use double quotes for strings and keys
- No trailing commas or comments
- Numbers, booleans, and null don't need quotes

