JSON Basics

Core JSON syntax, valid values, root structures, and foundational examples for working with JSON documents.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Valid JSON roots
Root object
{
  "name": "Ada",
  "active": true
}

# A JSON document can start with an object.

Root array
[
  { "id": 1 },
  { "id": 2 }
]

# A JSON document can start with an array.

Root string
"hello world"

# A single JSON string is also valid JSON.

Root number
42

# A number can be the entire JSON document.

Root null
null

# `null` is valid as a complete JSON document.

## Core syntax rules
Use double quotes for keys and strings
{
  "theme": "dark"
}

# JSON requires double quotes, not single quotes.

Do not use trailing commas
{
  "name": "Ada",
  "role": "admin"
}

# Trailing commas make JSON invalid.

Do not add comments
{
  "debug": false
}

# Standard JSON does not support comments.

Pretty-print JSON with jq
jq . input.json

# Format JSON into a readable structure.

Validate JSON with Python
python -m json.tool input.json > /dev/null

# Check whether a file parses as valid JSON.

Recommended next

No recommendations yet.