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:
â | { |
â | "antlr.org": { |
â | "owners" : [], |
â | "live" : âtrueâ, |
â | "speed" : 1âeâ100, |
â | "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 ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.