Skip to content
Back to Learn
·6 min read

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

TypeExampleGrammar RuleJSON RFC 8259 Definition
String"Hello, World!"A sequence of Unicode code points wrapped in double quotesSection 7: Strings are Unicode character sequences with escape sequences for special characters
Number42, -3.14, 1.5e10An optional minus sign, followed by integer or decimal digits, optional exponentSection 6: No distinction between integer and float, no octal/hex, no NaN/Infinity
Booleantrue, falseLiteral values, lowercase onlySection 3: Exactly two values
NullnullLiteral value, lowercase onlySection 3: Represents an intentionally absent value
Array[1, "two", null]Comma-separated values in square bracketsSection 5: Ordered list of zero or more values of any type
Object{"key": "value"}Comma-separated key-value pairs in curly bracesSection 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:

LanguageParse CodeResult TypeNotes
JavaScriptJSON.parse('"hello"')stringNative string type
Pythonjson.loads('"hello"')strUnicode string, no separate bytes type
Javamapper.readTree('"hello"')TextNodeUse .asText() to get String
Gojson.UnmarshalstringGo 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
LanguageParse 42Parse 3.14Parse 1e20Parse 9007199254740993
JavaScriptnumber (int)number (float)number (float)Loses precision (> Number.MAX_SAFE_INTEGER)
PythonintfloatfloatArbitrary precision (int)
JavaIntNode (int)DoubleNode (double)DoubleNode (double)LongNode or BigIntegerNode
Gofloat64float64float64float64 (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:

ValueJSON Valid?JavaScriptPythonJavaGo
nullYesnullNoneNullNodenil (interface)
"" (empty string)Yes"" (empty string)""""""
undefinedNoundefinedN/AN/AN/A
Missing keyN/AundefinedKeyErrornullZero 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

JSONJavaScriptPythonJava (Jackson)Go
StringstringstrString / TextNodestring
Number (integer)numberintint / Longfloat64
Number (float)numberfloatdouble / DoubleNodefloat64
Booleanbooleanboolboolean / BooleanNodebool
NullnullNonenull / NullNodenil
ArrayArraylistArray / ArrayNode[]interface{}
ObjectObjectdictMap / ObjectNodemap[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.