JSON Syntax Guide

Everything you need to know about JSON structure, rules, and formatting.

Basic Structure

JSON is built on two structures: objects and arrays. Every JSON document must be either an object or an array at the root level.

Object

{
  "key": "value"
}

Array

[
  "item1",
  "item2"
]

Objects

Objects are collections of key-value pairs enclosed in curly braces { }.

{
  "firstName": "John",
  "lastName": "Doe",
  "age": 30,
  "isEmployed": true,
  "address": {
    "street": "123 Main St",
    "city": "New York"
  }
}
  • • Keys must be strings in double quotes
  • • Key-value pairs are separated by colons
  • • Multiple pairs are separated by commas
  • • Objects can be nested inside other objects

Arrays

Arrays are ordered lists of values enclosed in square brackets [ ].

{
  "colors": ["red", "green", "blue"],
  "numbers": [1, 2, 3, 4, 5],
  "mixed": [1, "two", true, null],
  "nested": [[1, 2], [3, 4]],
  "objects": [
    {"name": "Alice"},
    {"name": "Bob"}
  ]
}
  • • Values are separated by commas
  • • Arrays can contain any data type
  • • Arrays can be nested
  • • Arrays maintain order

Data Types

JSON supports six data types:

String

Text enclosed in double quotes.

"Hello, World!"

Number

Integer or floating-point. No quotes.

42, 3.14, -17, 1.5e10

Boolean

True or false. Lowercase, no quotes.

true, false

Null

Represents empty or no value. Lowercase, no quotes.

null

Object

Collection of key-value pairs in curly braces.

{"key": "value"}

Array

Ordered list of values in square brackets.

[1, 2, 3]

String Escape Characters

Special characters in strings must be escaped with a backslash:

CharacterEscapeDescription
"\"Double quote
\\\Backslash
/\/Forward slash
Newline\nLine break
Tab\tTab character
Unicode\uXXXXUnicode character

Syntax Rules Summary

  • Use double quotes for all strings and keys
  • Separate items with commas
  • Use colon between key and value
  • No trailing commas
  • No comments
  • No single quotes
  • No undefined (use null)

Practice with Our JSON Formatter

Validate and format your JSON to ensure correct syntax.

Open JSON Formatter