JSON Data Types
JSON supports exactly six value types. Understanding them prevents most parsing errors and API mismatches.
1. String
"Hello, world!"
"2024-11-01T10:00:00Z"
""Strings must be enclosed in double quotes. The empty string "" is valid. Strings can contain any Unicode character except unescaped double quotes and backslashes.
2. Number
42
-7
3.14159
1.5e10JSON has one number type — it maps to IEEE 754 double-precision float. Integers up to 2^53−1 can be represented exactly. For larger integers, use strings. NaN, Infinity, and -Infinity are not valid.
3. Boolean
true
falseMust be lowercase. True, TRUE, 1, and 0 are not boolean JSON values.
4. Null
nullRepresents an intentionally absent value. Must be lowercase. Not the same as an absent key, an empty string, or 0 — each has different semantics.
5. Object
{
"username": "alice",
"age": 30,
"verified": true
}An ordered-by-insertion (in practice) collection of key-value pairs. Keys are always strings. Values can be any JSON type, including nested objects and arrays.
6. Array
[1, "two", false, null, {"nested": true}]An ordered list. Items can be any JSON type and can be mixed. There is no set, tuple, or typed-array equivalent in standard JSON.
Type Coercion Pitfalls
When parsing JSON in languages with weak typing, watch for:
- Large integers losing precision (
9007199254740993becomes9007199254740992in JavaScript) - Strings that look like numbers or booleans being coerced in CSV parsers
- Null vs undefined in JavaScript (JSON has no undefined)
- Dates — JSON has no date type; dates are strings (ISO 8601 by convention)
Tools
- JSON Formatter
- Tree Viewer — see types annotated per node
- JSON Syntax Guide