JSON Parser
Building a JSON parser with Galore
JSON Parser
This example shows how to build a complete JSON parser with Galore. The grammar handles all JSON value types: objects, arrays, strings, numbers, booleans, and null.
Try It
Edit the JSON input below and click Run to see the parse tree:
Grammar Breakdown
Token Definitions
NUMBER- JSON numbers with optional decimals and exponentsSTRING- Double-quoted strings%skip- Whitespace is ignored
Value Types
The Value rule is the entry point and can be any JSON type:
Dict- Curly braces with key-value pairsList- Square brackets with comma-separated valuesSTRING/NUMBER- Primitive typesBoolean-trueorfalse"null"- Null value
EBNF Features
This grammar uses EBNF notation for cleaner rules:
[ ... ]- Optional elements( ... )*- Zero or more repetitions
List -> "[" [ Value ( "," Value ) * ] "]" ;
Dict -> "{" [ Pair ("," Pair)* ] "}" ;
Example Inputs
Try these JSON values:
{"key": "value"}- Simple object[1, 2, 3]- Array of numbers{"nested": {"a": 1}}- Nested objectsnull- Just a null valuetrue- Boolean value