JSON Cheat Sheet
A quick reference for JSON syntax, data types, and common patterns.
Data Types
| Type | Example | Notes |
|---|---|---|
| String | "hello world" | Must use double quotes |
| Number | 42, 3.14, -1, 1.5e10 | No leading zeros, no hex/octal |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Object | {"key": "value"} | Keys must be double-quoted strings |
| Array | [1, 2, 3] | Ordered list of values |
Basic Structure
{
"name": "Alice",
"age": 30,
"active": true,
"address": {
"city": "New York",
"zip": "10001"
},
"tags": ["developer", "designer"],
"notes": null
}String Escaping
| Escape | Character |
|---|---|
\" | Double quote |
\\ | Backslash |
\n | Newline |
\t | Tab |
\r | Carriage return |
\uXXXX | Unicode character |
Common Mistakes
Trailing comma
{ "a": 1, "b": 2, } // ← Invalid!Single quotes
{ 'name': 'Alice' } // ← Invalid!Unquoted keys
{ name: "Alice" } // ← Invalid!Comments
{
// This is not allowed in JSON
"key": "value"
}Undefined values
{ "key": undefined } // ← Invalid! Use nullJSON vs JavaScript
| Feature | JSON | JavaScript |
|---|---|---|
| Quotes for keys | Required (double) | Optional |
| String quotes | Double only | Single, double, or backtick |
| Trailing commas | Not allowed | Allowed |
| Comments | Not allowed | Allowed |
| undefined | Not allowed | Valid value |