What is JSON?
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write, and strictly follows the RFC 8259 standard.
RFC 8259 Syntax Rules
RFC 8259 is the IETF specification that defines exactly what counts as valid JSON. Here is what it actually requires: the value types, the object and array grammar, and the things people assume are allowed but aren't.
The 7 value types
Per RFC 8259 §3, a JSON value MUST be one of exactly seven forms: an object, an array, a number, a string, or the three literal names true, false, and null. Nothing else is a valid JSON value.
Object syntax (name/value pairs)
{
"name": "value",
"count": 3,
"nested": { "ok": true }
}
An object begins with { and ends with }, and holds zero or more name/value pairs — a
string name, a colon (the "name-separator"), then a value.
Pairs are separated by a comma (the "value-separator").
Array syntax (including arrays of objects)
[
{ "id": 1, "name": "First" },
{ "id": 2, "name": "Second" }
]
An array begins with [ and ends with ], holding zero or more comma-separated values in order. Since
an object is itself a valid value, an array of objects is just an array whose elements happen to be objects — the grammar
doesn't define it as a separate structure.
What RFC 8259 does NOT allow
- Comments.
The grammar has no comment token at all —
//and/* */are simply undefined, so a strict parser treats them as a syntax error. - Trailing commas.
The value-separator only appears between members or
elements, never after the last one — a trailing comma
before
]or}is invalid. - Single-quoted strings or unquoted keys. Strings — including object names — must use double quotes. Single quotes and unquoted keys are not part of the JSON grammar.
- Leading zeros, NaN, or Infinity in numbers. The number grammar disallows a leading zero before other digits, and has no representation for non-finite values.
Data Types
JSON supports the following native data types:
- String A sequence of characters enclosed in double quotes (e.g.,
"Hello"). - Number Integer or floating-point (e.g.,
42,3.14). - Boolean
trueorfalse. - Null Represents an empty value (
null). - Array An ordered list of values enclosed in square brackets (
[]). - Object A collection of key/value pairs enclosed in curly braces (
{ }).
Syntax Rules
{
"string": "Keys must be double-quoted strings",
"number": 123,
"boolean": true,
"null_value": null,
"array": [
"No trailing commas are allowed in the last item",
2
],
"object": {
"nested": "structures work fine"
}
} Specifications & Standards
JSON is defined by several standards that have evolved over time. While they are mostly identical, understanding the differences can be helpful for strict compliance.
Current RFC 8259
The current IETF standard that obsoletes RFC 7159. It
specifies the application/json media type and defines JSON as a data-interchange format.
RFC 7159 & RFC 4627
Earlier versions of the JSON specification. RFC 7159 unified multiple previous documents, while RFC 4627 was the original RFC that first registered the media type.
ECMA-404
The Ecma International standard (4th edition, 2017) defines the syntax of JSON. It is 100% compatible with RFC 8259.
View ECMA-404 Standard