JSON Data Types Deep Dive: Understanding Every Type in Detail
JSON supports exactly six data types, and each has specific rules, edge cases, and behaviors that differ across programming languages. Understanding these types in depth will help you write better JSON, avoid subtle cross-language bugs, and design more robust data structures. This guide covers every type in detail with language-specific behavior tables. Use our JSON Validator to verify your type usage and JSON Type Detector to analyze types across your documents.
The Six JSON Data Types
| Type | Example | Grammar Rule | JSON RFC 8259 Definition |
|---|---|---|---|
| String | "Hello, World!" | A sequence of Unicode code points wrapped in double quotes | Section 7: Strings are Unicode character sequences with escape sequences for special characters |
| Number | 42, -3.14, 1.5e10 | An optional minus sign, followed by integer or decimal digits, optional exponent | Section 6: No distinction between integer and float, no octal/hex, no NaN/Infinity |
| Boolean | true, false | Literal values, lowercase only | Section 3: Exactly two values |
| Null | null | Literal value, lowercase only | Section 3: Represents an intentionally absent value |
| Array | [1, "two", null] | Comma-separated values in square brackets | Section 5: Ordered list of zero or more values of any type |
| Object | {"key": "value"} | Comma-separated key-value pairs in curly braces | Section 4: Unordered collection of key-value pairs, keys must be unique strings |
String Deep Dive
Strings are the most flexible JSON type but have strict escaping rules:
// Valid JSON strings
"Hello, World!"
"He said "Hello""
"Line 1\nLine 2"
"C:\Users\Alice"
"\u0048\u0065\u006c\u006c\u006f" // "Hello" in Unicode escapes
""
// Invalid JSON strings
'Hello' // Single quotes not allowed
"He said "Hi"" // Unescaped double quotes inside
"Hello\x" // Invalid escape sequence
String comparison across languages:
| Language | Parse Code | Result Type | Notes |
|---|---|---|---|
| JavaScript | JSON.parse('"hello"') | string | Native string type |
| Python | json.loads('"hello"') | str | Unicode string, no separate bytes type |
| Java | mapper.readTree('"hello"') | TextNode | Use .asText() to get String |
| Go | json.Unmarshal | string | Go strings are UTF-8 encoded |
Number Deep Dive
JSON numbers have no integer/float distinction, but languages do:
// Valid JSON numbers
42
-273.15
1.5e10
1.5E-10
0
-0
0.5
// Invalid JSON numbers
01 // Leading zero not allowed
0xFF // Hex not allowed
NaN // Not a number
Infinity // Infinity not allowed
1,000 // Comma not allowed
| Language | Parse 42 | Parse 3.14 | Parse 1e20 | Parse 9007199254740993 |
|---|---|---|---|---|
| JavaScript | number (int) | number (float) | number (float) | Loses precision (> Number.MAX_SAFE_INTEGER) |
| Python | int | float | float | Arbitrary precision (int) |
| Java | IntNode (int) | DoubleNode (double) | DoubleNode (double) | LongNode or BigIntegerNode |
| Go | float64 | float64 | float64 | float64 (precision loss) |
Boolean Deep Dive
Only true and false are valid. Quoted versions become strings:
// Valid
{"active": true, "verified": false}
// Invalid (parsed as strings, not booleans)
{"active": "true", "verified": "false"}
// Invalid JSON
{"active": True, "verified": FALSE}
Null Deep Dive
null represents an intentionally absent value. It is different from undefined (JavaScript), None (Python), nil (Go), or empty string:
| Value | JSON Valid? | JavaScript | Python | Java | Go |
|---|---|---|---|---|---|
null | Yes | null | None | NullNode | nil (interface) |
"" (empty string) | Yes | "" (empty string) | "" | "" | "" |
undefined | No | undefined | N/A | N/A | N/A |
| Missing key | N/A | undefined | KeyError | null | Zero value |
Array Deep Dive
Arrays are ordered lists of values. Types can be mixed, but this is generally bad practice:
// Recommended: homogeneous arrays
[1, 2, 3, 4, 5]
["apple", "banana", "cherry"]
[{"id": 1}, {"id": 2}, {"id": 3}]
// Technically valid but not recommended: mixed types
[1, "two", true, null, {"key": "value"}, [3, 4]]
Object Deep Dive
Objects are unordered collections of key-value pairs. Keys must be unique strings. Duplicate keys are technically allowed but the last value wins:
// Valid
{"name": "Alice", "age": 30, "active": true}
// Duplicate key: "name" will be "Bob" after parsing
{"name": "Alice", "name": "Bob"}
// Use our JSON Duplicate Key Detector to find these:
// /json-detect-duplicate-keys
Cross-Language Type Mapping: Full Reference
| JSON | JavaScript | Python | Java (Jackson) | Go |
|---|---|---|---|---|
| String | string | str | String / TextNode | string |
| Number (integer) | number | int | int / Long | float64 |
| Number (float) | number | float | double / DoubleNode | float64 |
| Boolean | boolean | bool | boolean / BooleanNode | bool |
| Null | null | None | null / NullNode | nil |
| Array | Array | list | Array / ArrayNode | []interface{} |
| Object | Object | dict | Map / ObjectNode | map[string]interface{} |
Type Detection and Analysis
For large JSON documents, use our JSON Type Detector to analyze types across all objects, detect inconsistencies, and ensure uniformity. This is especially important when consuming JSON from external APIs that may return unexpected types.
Next Steps
Validate your JSON types with our JSON Validator. Analyze type consistency with JSON Type Detector. For cross-language projects, use our code generators: JSON to TypeScript, JSON to Python, JSON to Go.