O'Reilly logo

The Definitive ANTLR 4 Reference, 2nd Edition by Terence Parr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing JSON

JSON is a text data format that captures a collection of name-value pairs, and since values can themselves be collections, JSON can include nested structures. Designing a parser for JSON gives us an opportunity to derive a grammar from a language reference manual[31] and to work with some more complicated lexical rules. To make things more concrete, here’s a simple JSON data file:

examples/t.json
 
{
 
"antlr.org": {
 
"owners" : [],
 
"live" : true,
 
"speed" : 1e100,
 
"menus" : [​"File"​, ​"Help\nMenu"​]
 
}
 
}

Our goal is to build an ANTLR grammar by reading the JSON reference manual and looking at its syntax diagram and existing grammar. We’ll pull out key phrases from the manual and figure out how to encode them as ANTLR rules, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required