JSON Types
JSON defines exactly 6 value types. Every JSON value is one of these. Understanding their encoding rules and edge cases prevents the most common JSON interoperability bugs.
6
Types
Primitive Types
String
§7A JSON string is a sequence of zero or more Unicode characters wrapped in double quotes. JSON strings support escape sequences for special characters: \" \\ \/ \b \f \n \r \t and \uXXXX for any Unicode code point. JSON strings must be UTF-8 encoded per RFC 8259.
Number
§6JSON has a single numeric type with no distinction between integers and floating-point. Numbers are IEEE 754 double-precision values. Integers are safe up to 2^53-1 (9,007,199,254,740,991). Beyond that, precision is lost. JSON has no NaN, Infinity, or -Infinity – these must use null or strings.
Boolean
§3JSON booleans are the lowercase literals true and false. No other casing is valid – True, False, TRUE, FALSE are all syntax errors. Boolean values are distinct from 0/1 and from the strings 'true'/'false'. JSON has no truthy/falsy concept – only strict true and false.
Null
§3JSON null represents the intentional absence of a value. It is a first-class type, not a string or number. null is distinct from undefined (JavaScript), None (Python), nil (Ruby/Go), and a missing key. A key with a null value exists in the object; a missing key does not.
Structural Types
Array
§5A JSON array is an ordered sequence of zero or more values enclosed in square brackets, separated by commas. Array elements can be any JSON value type including other arrays and objects. Element order is guaranteed and significant. Duplicate values are allowed.
Object
§4A JSON object is an unordered collection of zero or more key-value pairs enclosed in curly braces. Keys must be strings. Duplicate keys are allowed by the spec but produce undefined behavior. Object key order is not guaranteed by RFC 8259 – do not rely on insertion order.