JSON Syntax Cheat Sheet: Types, Escapes and Rules

By Undercover Nerd Project · Published November 12, 2026 · 4 min read

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

TypeExampleNotes
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.5e3Decimal only. No distinction between integers and decimals.
booleantrue, falseAlways lower case.
nullnullAlways 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:

EscapeMeaning
\"double quote
\\backslash
\/forward slash (optional, never required)
\b \fbackspace, form feed
\n \r \tline feed, carriage return, tab
\uXXXXa 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.

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

JSON compared with similar formats

FormatHow it differs from JSON
JavaScript object literalAllows single quotes, unquoted names, trailing commas, comments, functions, undefined and more. Every JSON document is valid JavaScript, but not the other way round.
Python dictionaryUses True, False, None and often single quotes. Convert with json.dumps instead of printing it.
YAMLDesigned for people to edit: indentation instead of brackets, comments allowed. YAML 1.2 accepts JSON as valid input.
JSON5 and JSONCJSON with extras (comments, trailing commas, unquoted names). Parsers for plain JSON will reject them.
JSON LinesOne complete JSON value per line, handy for logs and large streams. The whole file is not a single JSON document.

Practical conventions

If a document fails to parse, the common JSON errors guide walks through the usual causes and how to track them down.

More guides