AI Generate JSON docs instantly

JSON Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

3 snippets

JSON basics and syntax rules

Basic Structure

{
  "key": "value"
}

Comments

// JSON does NOT support comments
// Use JSDoc or remove before parsing

Key Rules

// Keys MUST be quoted strings
{
  "name": "valid",
  name: "invalid"
}

Data Types

5 snippets

Supported value types

String

{
  "name": "John",
  "city": "New York"
}

Number

{
  "age": 30,
  "price": 19.99,
  "negative": -5,
  "scientific": 1.2e+3
}

Boolean

{
  "isActive": true,
  "isDeleted": false
}

Null

{
  "value": null
}

No Undefined

// JSON does NOT support undefined
// Use null instead

Arrays

5 snippets

Ordered lists of values

Simple Array

{
  "fruits": ["apple", "banana", "orange"]
}

Mixed Types

{
  "mixed": [1, "two", true, null]
}

Nested Arrays

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

Array of Objects

{
  "users": [
    {"name": "Alice", "age": 25},
    {"name": "Bob", "age": 30}
  ]
}

Empty Array

{
  "items": []
}

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Objects

4 snippets

Key-value pairs

Simple Object

{
  "person": {
    "name": "John",
    "age": 30
  }
}

Nested Objects

{
  "user": {
    "profile": {
      "name": "John",
      "address": {
        "city": "NYC"
      }
    }
  }
}

Empty Object

{
  "config": {}
}

Object with Arrays

{
  "person": {
    "name": "John",
    "hobbies": ["reading", "coding"]
  }
}

Special Characters

3 snippets

Escaping and Unicode

Escape Sequences

{
  "quote": "\"Hello\"",
  "backslash": "\\",
  "newline": "Line 1\nLine 2",
  "tab": "Col1\tCol2"
}

Unicode

{
  "unicode": "\u0041",
  "emoji": "\uD83D\uDE00"
}

Valid Escapes

\" \\ \/ \b \f \n \r \t \uXXXX

Formatting

3 snippets

Readable vs compact

Pretty Printed

{
  "name": "John",
  "age": 30,
  "hobbies": [
    "reading",
    "coding"
  ]
}

Compact (Minified)

{"name":"John","age":30,"hobbies":["reading","coding"]}

No Trailing Commas

// Invalid:
{
  "a": 1,
  "b": 2,
}

// Valid:
{
  "a": 1,
  "b": 2
}

Common Patterns

4 snippets

Real-world usage examples

API Response

{
  "status": "success",
  "data": {
    "id": 1,
    "name": "Product"
  },
  "message": "Retrieved"
}

Config File

{
  "app": {
    "name": "MyApp",
    "version": "1.0.0",
    "port": 3000
  }
}

Package.json

{
  "name": "my-package",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.18.0"
  }
}

Error Response

{
  "error": {
    "code": 404,
    "message": "Not Found",
    "details": []
  }
}

Limitations

5 snippets

What JSON cannot do

No Comments

// Cannot include comments in JSON
// Remove before parsing

No Functions

// Cannot include functions
{
  "invalid": function() {}
}

No Dates

// No native date type
{
  "date": "2024-01-01T00:00:00Z"
}

No Undefined/NaN/Infinity

// Use null instead
{
  "value": null
}

No Trailing Commas

// Last item cannot have comma
{
  "a": 1  // OK
}

More Cheat Sheets

FAQ

Frequently asked questions

What is a JSON cheat sheet?

A JSON cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in JSON. It helps developers quickly look up syntax without searching through documentation.

How do I learn JSON quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important JSON concepts?

Key JSON concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my JSON code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your JSON code using AI.

Code Conversion Tools

Convert JSON to Other Languages

Easily translate your JSON code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate JSON Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week