JSON Grammar & Syntax Diagrams

Interactive railroad diagrams visualizing the official JSON specification

Live JSON Parser Visualization

Type or paste JSON below to see which grammar rules are applied in real-time:

Enter JSON to see the parsing visualization
Terminal (literal characters)
Non-terminal (grammar rule)
Rail (path)
Active (currently parsing)

value

Root Rule

A JSON value can be a string, number, object, array, boolean, or null:

string number object array true false null
value ::= string | number | object | array | "true" | "false" | "null"

object

Container

An object is an unordered set of name/value pairs enclosed in curly braces:

{ ws string ws : value , ws }
object ::= "{" ws [ member ( "," member )* ] ws "}"
member ::= string ws ":" value

array

Container

An array is an ordered collection of values enclosed in square brackets:

[ ws value , ws ]
array ::= "[" ws [ value ( "," value )* ] ws "]"

string

Primitive

A string is a sequence of Unicode characters wrapped in double quotes:

" Unicode char \ escape char "
string ::= '"' character* '"'
character ::= unescaped | '\' ( " | \ | / | b | f | n | r | t | u hex{4} )

number

Primitive

A number can be an integer, decimal, or use scientific notation:

- 0 1-9 digits . digits e/E ± digits
number ::= "-"? ( "0" | digit1-9 digits* ) ( "." digits+ )? ( [eE] [+-]? digits+ )?

whitespace

Utility

Whitespace can be inserted between any pair of tokens:

space \t \n
ws ::= ( ' ' | '\t' | '\n' | '\r' )*

Official JSON Specifications

JSON is defined by two complementary standards: