All cheat sheets

JSON Cheat Sheet

Quick reference for JSON syntax, data types, escaping, and common pitfalls — with examples.

Data Formats
json
data-formats

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.

Table
TypeNotationNotes
string"text"Double-quoted; backslash-escaped.
number42, -3.14, 1.5e10No 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.
booleantrue / falseLowercase only.
nullnullLowercase 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.

json
{
  "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.

json
[
  "string",
  42,
  true,
  null,
  { "nested": "object" },
  ["another", "array"]
]

Numbers

Table
FormExampleValid?
Integer0, -42Yes
Fraction3.14, 0.5Yes
Exponent1.5e10, 2E-3Yes
Leading zero042No
Plus sign+42No
NaNNo
InfinityNo
Hexadecimal0xFFNo
Octal0777No

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.

Table
EscapeMeaning
\"Double quote
\\Backslash
\/Forward slash (optional, often unescaped)
\bBackspace (U+0008)
\fForm feed (U+000C)
\nLine feed (U+000A)
\rCarriage return (U+000D)
\tTab (U+0009)
\uXXXXUnicode code point (4 hex digits)

Anything else after \ is invalid. Common mistakes:

json
{
  "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

Table
ConstructJSONJavaScript object literal
"a": 1OKOK
'a': 1NoOK
a: 1NoOK
{ "a": 1, }NoOK
[1, 2,]NoOK
// commentNoOK
/* comment */NoOK
{ "a": undefined }NoOK
{ "a": NaN }NoOK
{ "a": 1e1000 }NoDepends on the engine

A small invalid file:

json
{
  // 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

json
{
  "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.

jsonl
{"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.

References