JSON Cheat Sheet
Quick reference for JSON syntax, data types, escaping, and common pitfalls — with examples.
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format defined by RFC 8259 and documented at json.org. It is the default payload format for REST APIs, configuration files (package.json, tsconfig.json), and most NoSQL data stores. JSON is intentionally minimal: a small set of value types, no comments, no trailing commas, double quotes only.
Value types
A JSON document is a single value drawn from exactly six types.
| Type | Notation | Notes |
|---|---|---|
string | "text" | Double-quoted; backslash-escaped. |
number | 42, -3.14, 1.5e10 | No leading zeros; no NaN, Infinity, or hex. |
object | { "key": value, ... } | Unordered collection of string-keyed pairs. |
array | [ value, value, ... ] | Ordered list; values may be heterogeneous. |
boolean | true / false | Lowercase only. |
null | null | Lowercase only; distinct from "null" and 0. |
There is no undefined, no NaN, no Infinity, no Date, no Map, no comments. If you need any of those, you are outside the spec.
Objects
An object is a comma-separated list of key/value pairs wrapped in {}. Keys must be double-quoted strings. Whitespace between tokens is ignored. Trailing commas are not allowed.
{
"name": "Ada Lovelace",
"born": 1815,
"languages": ["English", "French"],
"alive": false,
"spouse": null
}
Arrays
An array is an ordered, comma-separated list of values wrapped in []. Values may be of mixed types.
[
"string",
42,
true,
null,
{ "nested": "object" },
["another", "array"]
]
Numbers
| Form | Example | Valid? |
|---|---|---|
| Integer | 0, -42 | Yes |
| Fraction | 3.14, 0.5 | Yes |
| Exponent | 1.5e10, 2E-3 | Yes |
| Leading zero | 042 | No |
| Plus sign | +42 | No |
NaN | — | No |
Infinity | — | No |
| Hexadecimal | 0xFF | No |
| Octal | 0777 | No |
JSON has exactly one numeric type (IEEE-754 double-precision in most languages). Use strings if you need arbitrary precision (for example, 64-bit integers).
Strings and escaping
Strings are sequences of Unicode characters wrapped in double quotes. The backslash \ introduces an escape sequence. All other characters may appear literally — including single quotes, which is why "can't" is fine.
| Escape | Meaning |
|---|---|
\" | Double quote |
\\ | Backslash |
\/ | Forward slash (optional, often unescaped) |
\b | Backspace (U+0008) |
\f | Form feed (U+000C) |
\n | Line feed (U+000A) |
\r | Carriage return (U+000D) |
\t | Tab (U+0009) |
\uXXXX | Unicode code point (4 hex digits) |
Anything else after \ is invalid. Common mistakes:
{
"valid": "He said \"hi\"",
"also-ok": "C:\\Users\\ada",
"linebreak": "line1\nline2",
"unicode": "snowman \u2603",
"invalid": "bad \q escape"
}
The last line fails because \q is not a defined escape.
Valid vs invalid at a glance
| Construct | JSON | JavaScript object literal |
|---|---|---|
"a": 1 | OK | OK |
'a': 1 | No | OK |
a: 1 | No | OK |
{ "a": 1, } | No | OK |
[1, 2,] | No | OK |
// comment | No | OK |
/* comment */ | No | OK |
{ "a": undefined } | No | OK |
{ "a": NaN } | No | OK |
{ "a": 1e1000 } | No | Depends on the engine |
A small invalid file:
{
// comment — not allowed
name: "Ada", // unquoted key
"age": 36, // OK
"city": 'Paris', // single quotes
"hobbies": ["math",] // trailing comma
}
Every line except age violates RFC 8259.
Nested example
{
"id": "evt_01HXYZ",
"type": "order.placed",
"createdAt": "2026-07-28T10:42:00Z",
"data": {
"orderId": 1042,
"customer": {
"id": "cus_8a2",
"email": "ada@example.com",
"tags": ["vip", "newsletter"]
},
"items": [
{ "sku": "BK-001", "qty": 1, "price": 29.9 },
{ "sku": "PN-042", "qty": 2, "price": 4.5 }
],
"shipped": null
}
}
JSON vs JSONL
JSONL (JSON Lines) is a different format: one JSON value per line, no enclosing array, no commas between lines. It is the standard for streaming, log files, and bulk-loading into document databases.
{"id": 1, "name": "Ada"}
{"id": 2, "name": "Linus"}
{"id": 3, "name": "Grace"}
A regular JSON file wraps those records in an array with commas. JSONL is harder to read line-by-line but is appendable and stream-friendly.