JSON Value Types and Syntax Reference
JSON has six value types: object, array, string, number, boolean, and null. It carries data, not comments, dates, binary values, functions, or object references unless a separate contract defines an encoding.
| Type | Example | Notes |
|---|---|---|
| object | {"name":"Ada"} | String names mapped to values. |
| array | [1,2,3] | Ordered sequence of values. |
| string | "hello" | Double-quoted Unicode text with escapes. |
| number | -12.5e2 | Decimal syntax without NaN or Infinity. |
| boolean | true | Lowercase true or false. |
| null | null | An explicit null value. |
Objects
An object uses braces and separates name-value members with commas. Names are strings in double quotes. JSON interoperability is best when names are unique; duplicate names can be kept first, kept last, reported, or exposed as duplicates depending on the parser. Security-sensitive boundaries should reject ambiguous duplicates before different services interpret them differently.
Arrays
An array uses brackets and preserves element order. Values can have different JSON types, but schemas often require one consistent item shape. There are no holes or trailing commas. Large arrays can consume substantial memory when a parser builds the entire tree; use size limits, pagination, or a streaming format such as JSON Lines where the contract permits.
Strings and escapes
Strings use double quotes. Escape quotation mark, reverse solidus, and control characters with sequences such as \", \\, \n, and \t. A Unicode escape uses \u followed by four hexadecimal digits; characters outside that range can be represented by a surrogate pair. Transport JSON as UTF-8 for interoperability.
Numbers
JSON number syntax supports an optional minus, integer part, optional fraction, and optional exponent. Leading plus signs, hexadecimal, NaN, and Infinity are not valid JSON. The format does not specify a machine precision, so producers should consider consumer limits. Use strings for 64-bit identifiers or exact decimals when a target number type would round them, and document the conversion.
Boolean and null
Booleans are lowercase true and false, not quoted strings or numeric flags. Null is an explicit value and differs from an absent object member. A schema should state whether a property is required, whether null is allowed, and what omission means. Avoid converting every missing value to null when patch semantics distinguish “unchanged” from “clear this field.”
Top-level values and whitespace
A JSON text can contain any JSON value at the top level, including an array, string, number, boolean, or null. An API can impose a stricter object-only contract. Insignificant whitespace can appear around structural tokens, but comments are not part of standard JSON. A byte-order mark and non-UTF encodings can cause interoperability problems.
Missing native types
Represent timestamps as documented strings or numbers, binary data as a transport-specific form such as Base64 or multipart content, and maps as objects with string names. JSON cannot express circular references. Do not invent a marker convention unless both producer and consumer share a schema for it.
Frequently Asked Questions
Can top-level JSON be an array?
Yes, unless the application contract restricts it.
Are duplicate names safe?
No. Parser behavior differs.
Are all 64-bit integers exact in JavaScript?
No. Use a documented string representation when needed.