JSON Syntax Cheat Sheet: Types, Escapes and Rules
One page with every JSON data type, the string escapes, the number rules and the differences from JavaScript objects, YAML and Python dictionaries.
JSON is small enough to learn in a few minutes, and strict enough that a single stray character breaks it. This is a one-page reference for the whole format: its six value types, the string and number rules, what is and is not allowed, and how it differs from the formats it is most often confused with. It follows the official specifications, RFC 8259 and ECMA-404.
The six value types
| Type | Example | Notes |
|---|---|---|
| object | {"name": "Ana", "age": 30} | Unordered name/value pairs. Every name is a string in double quotes. |
| array | [1, "two", null] | An ordered list. Items can be of different types. |
| string | "hello" | Double quotes only. Unicode text with escapes. |
| number | -12.5e3 | Decimal only. No distinction between integers and decimals. |
| boolean | true, false | Always lower case. |
| null | null | Always lower case. Means "no value". |
A JSON document is any one of these values. Older versions of the specification required the top level to be an object or an array, but the current one allows any value, so a file containing just 42 or "text" is valid.
Objects and arrays
Items are separated by commas, names are separated from values by a colon, and there is never a comma after the last item. Objects and arrays can be nested to any depth.
{
"id": 17,
"tags": ["a", "b"],
"address": {"city": "Ottawa", "postcode": null}
}
Object names should be unique. The specification says they "SHOULD" be, not "MUST", and different parsers handle duplicates differently: most keep the last one, some keep the first. Treat duplicate names as a bug. Also remember that the order of an object's names has no meaning in JSON, even though most parsers preserve it.
Strings
A string is wrapped in double quotes and may contain any Unicode character except the double quote, the backslash and control characters below U+0020 (including line breaks and tabs), which must be escaped. The escapes are:
| Escape | Meaning |
|---|---|
\" | double quote |
\\ | backslash |
\/ | forward slash (optional, never required) |
\b \f | backspace, form feed |
\n \r \t | line feed, carriage return, tab |
\uXXXX | a character by its four-digit hexadecimal code, for example \u00e9 is é |
Characters outside the basic range can be written directly (JSON text exchanged between systems should be UTF-8) or as a pair of \u escapes. A single backslash followed by any other character is an error.
Numbers
The grammar is short: an optional minus sign, an integer part, an optional fraction and an optional exponent.
- No leading zeros:
007is invalid,0.7and7are valid. - No leading plus sign:
+5is invalid. - A digit is required on both sides of the decimal point:
.5and5.are invalid. - No hexadecimal, octal or binary:
0xFFis invalid. - No
NaN,Infinityor-Infinity. - Exponents are allowed:
1.5e3and2E-4.
JSON does not say how many digits a number may have or how it is stored. JavaScript reads every number as a 64-bit floating-point value, which represents whole numbers exactly only up to 9,007,199,254,740,991 (2 to the power 53, minus 1). Larger identifiers, such as some database IDs, can silently lose their last digits. If an ID can be that large, send it as a string.
Whitespace
Only four characters count as whitespace outside strings: space, tab, line feed and carriage return. Other space-like characters, including the non-breaking space that appears in text copied from web pages, are errors. Whitespace between values is ignored, which is why formatting and minifying change a document's size but not its meaning.
What JSON does not have
- Comments of any kind.
- Dates. Write them as strings, usually in ISO 8601 form such as
"2026-11-12T09:30:00Z", and convert them in your own code. - Binary data. Encode it as text, commonly Base64.
- Undefined, functions, and special values such as NaN. JavaScript's
JSON.stringifysilently omits properties whose value isundefinedor a function, and writesNaNasnull. - References or variables. Every value stands alone.
JSON compared with similar formats
| Format | How it differs from JSON |
|---|---|
| JavaScript object literal | Allows single quotes, unquoted names, trailing commas, comments, functions, undefined and more. Every JSON document is valid JavaScript, but not the other way round. |
| Python dictionary | Uses True, False, None and often single quotes. Convert with json.dumps instead of printing it. |
| YAML | Designed for people to edit: indentation instead of brackets, comments allowed. YAML 1.2 accepts JSON as valid input. |
| JSON5 and JSONC | JSON with extras (comments, trailing commas, unquoted names). Parsers for plain JSON will reject them. |
| JSON Lines | One complete JSON value per line, handy for logs and large streams. The whole file is not a single JSON document. |
Practical conventions
- The file extension is
.jsonand the media type isapplication/json. - Two-space indentation is the most common style for human-readable files. Minified JSON, with no extra whitespace, is the norm for network transfer.
- Name properties consistently, for example always
camelCaseor alwayssnake_case, so that your data is predictable to read. - Validate data before you rely on it. A document can be valid JSON and still have the wrong shape for your program.
If a document fails to parse, the common JSON errors guide walks through the usual causes and how to track them down.