JSON Cheat Sheet 2026

Complete quick reference guide for JSON syntax, data types, and usage

🔧 JSON Tools

Quick Facts

Stands for: JavaScript Object Notation
Created by: Douglas Crockford (2001)
MIME Type: application/json
File Extension: .json
Encoding: UTF-8 (recommended)
Use Cases: APIs, Config Files, Data Storage

Syntax Rules

  • Data is in name/value pairs: "key": "value"
  • Data is separated by commas
  • Curly braces hold objects: {}
  • Square brackets hold arrays: []
  • Keys must be strings in double quotes
  • No trailing commas allowed
  • No comments allowed (not in standard JSON)
  • No undefined values

Data Types

String
"Hello World"
Double quotes required, escape special chars with \
Number
42, 3.14, -10, 1.5e10
Integer or decimal, can be negative, scientific notation allowed
Boolean
true, false
Lowercase only
Null
null
Represents absence of value
Object
{"name": "John", "age": 30}
Unordered collection of key/value pairs
Array
[1, 2, 3]
Ordered list of values, can mix types

Common Patterns

Simple Object

{
  "name": "John Doe",
  "age": 30,
  "email": "john@example.com",
  "active": true
}

Nested Object

{
  "user": {
    "name": "John Doe",
    "address": {
      "street": "123 Main St",
      "city": "New York"
    }
  }
}

Array of Objects

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

API Response

{
  "status": "success",
  "data": {
    "items": [...],
    "total": 100,
    "page": 1
  },
  "timestamp": "2026-03-03T10:30:00Z"
}

Code Examples

JavaScript

// Parse JSON string
const data = JSON.parse('{"name":"John","age":30}');

// Stringify object
const jsonStr = JSON.stringify(data, null, 2);

// With error handling
try {
  const parsed = JSON.parse(jsonString);
} catch (error) {
  console.error('Invalid JSON:', error);
}

Python

import json

# Parse JSON string
data = json.loads('{"name":"John","age":30}')

# Convert to JSON
json_str = json.dumps(data, indent=2)

# Read from file
with open('data.json', 'r') as f:
    data = json.load(f)

# Write to file
with open('output.json', 'w') as f:
    json.dump(data, f, indent=2)

Java

// Using Jackson
ObjectMapper mapper = new ObjectMapper();

// Parse JSON
User user = mapper.readValue(jsonString, User.class);

// Convert to JSON
String json = mapper.writeValueAsString(user);

// Pretty print
String prettyJson = mapper
    .writerWithDefaultPrettyPrinter()
    .writeValueAsString(user);

PHP

// Decode JSON
$data = json_decode($jsonString, true);

// Encode to JSON
$json = json_encode($data, JSON_PRETTY_PRINT);

// With error checking
$data = json_decode($jsonString);
if (json_last_error() !== JSON_ERROR_NONE) {
    echo 'JSON Error: ' . json_last_error_msg();
}

Escape Sequences

\"Double quote
\\Backslash
\/Forward slash
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tTab
\uXXXXUnicode character (4 hex digits)

Common Errors & Fixes

Trailing comma
❌ Wrong:{"name": "John", "age": 30,}
✅ Right:{"name": "John", "age": 30}
Single quotes
❌ Wrong:{'name': 'John'}
✅ Right:{"name": "John"}
Unquoted keys
❌ Wrong:{name: "John"}
✅ Right:{"name": "John"}
Missing comma
❌ Wrong:{"name": "John" "age": 30}
✅ Right:{"name": "John", "age": 30}
Comments (not allowed)
❌ Wrong:{"name": "John" /* comment */}
✅ Right:{"name": "John"}

Best Practices

Use consistent formatting: Choose 2 or 4 spaces for indentation
Validate before deployment: Use validators to catch errors early
Use meaningful keys: Choose descriptive property names
Keep structure flat when possible: Avoid unnecessary nesting
Use camelCase or snake_case consistently: Pick one naming convention
Include timestamps in ISO 8601 format: "2026-03-03T10:30:00Z"
Compress for production: Use minified JSON for APIs
Handle parsing errors gracefully: Always use try-catch blocks

Useful Tools & Resources

BigJSON.online - Free JSON Tools & Resources

Last updated: March 2026 | Share this cheat sheet with your team!