JSON Syntax Cheat Sheet

Everything you need to know about JSON syntax on a single page. Data types, escape sequences, rules, and common pitfalls — all in quick-reference tables.

JSONTech TeamMarch 10, 20255 min read

Data Types

JSON supports exactly six data types:

TypeSyntaxExampleNotes
StringDouble-quoted text"hello"Must use double quotes, not single
NumberInteger or float42, 3.14, -1, 2.5e10No hex, octal, NaN, or Infinity
Booleantrue / falsetrueLowercase only — True is invalid
NullnullnullLowercase only — None, NULL invalid
Object{ } with key-value pairs{"a": 1}Keys must be double-quoted strings
Array[ ] with ordered values[1, "two", null]Elements can be mixed types

String Escape Sequences

These are the only valid escape sequences inside JSON strings:

SequenceMeaningExample
\\"Double quote"She said \\"hi\\""
\\\\Backslash"C:\\\\Users\\\\file"
\\/Forward slash"date: 2025\\/03\\/10"
\\bBackspace"back\\bspace"
\\fForm feed"form\\ffeed"
\\nNewline"line1\\nline2"
\\rCarriage return"return\\rhere"
\\tTab"col1\\tcol2"
\\uXXXXUnicode character (4 hex digits)"\\u00e9" → é

Syntax Rules

RuleValid ✓Invalid ✗Why
Keys must be double-quoted{"name": "Jo"}{name: "Jo"}Unquoted keys are not allowed
Strings use double quotes only"hello"'hello'Single quotes are not valid JSON
No trailing commas{"a": 1, "b": 2}{"a": 1, "b": 2,}Trailing commas cause parse errors
No comments{"a": 1}{"a": 1} // noteJSON has no comment syntax
No undefined{"a": null}{"a": undefined}Use null instead
No hex numbers2550xFFOnly decimal notation allowed
No leading zeros0.5007Leading zeros are not valid
No NaN or InfinitynullNaN, InfinityUse null or a string representation

Object Syntax

An object is an unordered set of key-value pairs wrapped in curly braces:

{
  "name": "Alice",
  "age": 30,
  "active": true,
  "address": {
    "street": "123 Main St",
    "city": "Portland"
  },
  "tags": ["admin", "user"]
}
RuleDetail
DelimiterCurly braces { }
Key-value separatorColon :
Pair separatorComma ,
KeysMust be unique double-quoted strings
ValuesAny valid JSON type
Empty object{} is valid

Array Syntax

An array is an ordered list of values wrapped in square brackets:

["apple", "banana", "cherry"]

[1, "mixed", true, null, {"nested": "ok"}, [1, 2]]

[]
RuleDetail
DelimiterSquare brackets [ ]
Element separatorComma ,
Element typesAny valid JSON type (can be mixed)
OrderingPreserved — order matters
Empty array[] is valid

Nesting Rules

What Can Be NestedExample
Object inside object{"user": {"name": "Jo"}}
Array inside object{"ids": [1, 2, 3]}
Object inside array[{"id": 1}, {"id": 2}]
Array inside array[[1, 2], [3, 4]]

There is no formal depth limit in the JSON spec, but most parsers cap recursion around 100–512 levels. Keep nesting shallow (3–4 levels) for readability.

Common Gotchas

MistakeCorrect VersionError You'll See
{name: "Jo"}{"name": "Jo"}Unexpected token n
{'name': 'Jo'}{"name": "Jo"}Unexpected token '
{"a": 1,}{"a": 1}Unexpected token }
{"a": undefined}{"a": null}Unexpected token u
{"a": NaN}{"a": null}Unexpected token N
[1, 2, 3,][1, 2, 3]Unexpected token ]
{"a": 0xFF}{"a": 255}Unexpected token x
Unescaped newline in stringUse \\n insteadUnterminated string

File Extension & MIME Type

PropertyValue
File extension.json
MIME typeapplication/json
HTTP Content-Type headerContent-Type: application/json; charset=utf-8
Default encodingUTF-8
RFC specificationRFC 8259 (supersedes RFC 7159, RFC 4627)
ECMA standardECMA-404

Validate your JSON instantly: Paste any JSON into our JSON Formatter to detect syntax errors, auto-fix trailing commas, and pretty-print with one click.

Related Tools