JSON Cheatsheet & Quick Reference

JSON Formatter Hub

JSON Cheatsheet & Quick Reference

This page is a compact reference for JSON syntax. Use the JSON Formatter to try any of these examples directly โ€” paste them in and explore the tree view to understand the structure.

Data Types

JSON has exactly six value types:

{
  "stringValue":  "Hello, world!",
  "integerValue": 42,
  "floatValue":   3.14159,
  "booleanTrue":  true,
  "booleanFalse": false,
  "nullValue":    null
}
Type Example Notes
String "Hello" Must use double quotes. Single quotes are invalid.
Number 42, -7, 3.14, 1e5 No leading zeros. No quotes. Scientific notation allowed.
Boolean true, false Lowercase only. True or TRUE are invalid.
Null null Lowercase only. Represents no value.
Object {"key": "value"} Unordered key-value pairs. Keys must be strings.
Array [1, 2, 3] Ordered list. Elements can be any type.

Object Syntax

{
  "key": "value",
  "anotherKey": 123,
  "lastKey": true
}

Array Syntax

["apple", "banana", "cherry"]
[1, 2.5, true, null, "mixed", {"nested": "object"}]

Nested Structures

Object inside an Object

{
  "user": {
    "id": 1,
    "name": "Alice",
    "address": {
      "street": "123 Main St",
      "city": "London",
      "country": "UK"
    }
  }
}

Array of Objects

{
  "users": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"},
    {"id": 3, "name": "Charlie"}
  ]
}

Array of Arrays (Matrix)

{
  "matrix": [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ]
}

Mixed Deep Nesting

{
  "order": {
    "id": "ORD-001",
    "customer": {
      "name": "Alice",
      "email": "alice@example.com"
    },
    "items": [
      {
        "productId": "P101",
        "name": "Widget",
        "quantity": 2,
        "price": 9.99,
        "tags": ["electronics", "small"]
      }
    ],
    "total": 19.98,
    "paid": true,
    "notes": null
  }
}

String Escape Sequences

Special characters inside JSON strings must be escaped with a backslash:

Escape Meaning Example
\" Double quote "He said \"hello\""
\\ Backslash "C:\\Users\\Alice"
\/ Forward slash (optional) "https:\/\/example.com"
\n Newline "Line 1\nLine 2"
\r Carriage return "Line 1\r\nLine 2"
\t Tab "col1\tcol2"
\uXXXX Unicode code point "รฉ" โ†’ รฉ

Common JSON Patterns

API Response Envelope

{
  "status": "success",
  "data": {
    "id": 42,
    "name": "Widget"
  },
  "message": null,
  "timestamp": "2025-05-10T09:00:00Z"
}

Paginated List Response

{
  "page": 1,
  "perPage": 20,
  "total": 143,
  "data": [
    {"id": 1, "name": "Item 1"},
    {"id": 2, "name": "Item 2"}
  ]
}

Error Response

{
  "status": "error",
  "code": 404,
  "message": "Resource not found",
  "details": {
    "field": "userId",
    "reason": "No user with id 9999"
  }
}

Configuration File Pattern

{
  "appName": "my-service",
  "version": "2.1.0",
  "server": {
    "host": "0.0.0.0",
    "port": 8080,
    "debug": false
  },
  "database": {
    "host": "db.example.com",
    "port": 5432,
    "name": "production_db",
    "ssl": true
  },
  "features": {
    "darkMode": true,
    "betaFeatures": false
  },
  "allowedOrigins": [
    "https://app.example.com",
    "https://www.example.com"
  ]
}

GeoJSON Point (a standard JSON-based format)

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [-0.1276, 51.5074]
  },
  "properties": {
    "name": "London"
  }
}

What JSON Does NOT Support

Not Allowed Workaround
Comments (// or /* */) Use a separate docs file or JSON5 if your toolchain supports it
Single-quoted strings ('value') Always use double quotes: "value"
Trailing commas ([1, 2,]) Remove the last comma
Unquoted keys ({key: 1}) Quote all keys: {"key": 1}
Leading zeros in numbers (007) Use 7 (or "007" as a string if zero-padding matters)
Native date type Encode as ISO 8601 string: "2025-05-10T09:00:00Z"
undefined Use null to represent the absence of a value
Functions or code JSON is data only โ€” no executable content
Binary data (images, files) Encode as Base64 string
Infinity / NaN Use null or a sentinel string like "Infinity"

JSON Validator Checklist

Before submitting a JSON payload to an API or saving a config file, verify:

  1. All string keys are in double quotes
  2. All string values are in double quotes
  3. No trailing commas after the last key-value pair or array element
  4. Opening and closing braces and brackets are balanced
  5. Boolean values are lowercase true / false
  6. Null values are lowercase null
  7. No JavaScript-only features: no comments, no undefined, no functions
  8. Special characters inside strings are properly escaped

Run your JSON through the JSON Formatter & Validator to check all of the above automatically. Use the Auto-fix button to repair the most common issues.

Related Guides