JSON Cheat Sheet

A quick reference for JSON syntax, data types, and common patterns.

Data Types

TypeExampleNotes
String"hello world"Must use double quotes
Number42, 3.14, -1, 1.5e10No leading zeros, no hex/octal
Booleantrue, falseLowercase only
NullnullLowercase 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

EscapeCharacter
\"Double quote
\\Backslash
\nNewline
\tTab
\rCarriage return
\uXXXXUnicode 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 null

JSON vs JavaScript

FeatureJSONJavaScript
Quotes for keysRequired (double)Optional
String quotesDouble onlySingle, double, or backtick
Trailing commasNot allowedAllowed
CommentsNot allowedAllowed
undefinedNot allowedValid value