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 exponents
  • STRING - 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 pairs
  • List - Square brackets with comma-separated values
  • STRING / NUMBER - Primitive types
  • Boolean - true or false
  • "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 objects
  • null - Just a null value
  • true - Boolean value