Translating JSON to XML
Lots of web services return JSON data, and we might run into a situation where we want to feed some JSON data into existing code that accepts only XML. Letâs use our JSON grammar from âParsing JSONâ as a foundation to build a JSON to XML translator. Our goal is to read in JSON text like this:
â | { |
â | â"description"â â:â â"An imaginary server config file"â, |
â | â"logs"â â:â {â"level"ââ:ââ"verbose"â, â"dir"ââ:ââ"/var/log"â}, |
â | â"host"â â:â â"antlr.org"â, |
â | â"admin"ââ:â [â"parrt"â, â"tombu"â], |
â | â"aliases"ââ:â [] |
â | } |
and emit XML in an equivalent form, like this:
â | <description>An imaginary server config ... |
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.