We’ll look at what Groovy provides for reading and parsing JSON and XML. If you missed the last tutorial, check it out or take a look at the who

Tame JSON and XML with Apache Groovy - OpenSource.net

submited by
Style Pass
2024-05-04 02:00:01

We’ll look at what Groovy provides for reading and parsing JSON and XML. If you missed the last tutorial, check it out or take a look at the whole series.

Most Linux installations provide lots of example JSON files; in my case, I found a moderately complicated one in /usr/share/iso-codes/json/schema-15924.json that looks like this:

Line three instantiates a File object associated with that file name and then uses the parse() method of JsonSlurper to parse it.

Handling XML is quite similar. In particular, there’s a package groovy.xml that contains a class XmlSlurper that bears marked similarity to JsonSlurper.

A file I found on my system at /usr/share/help-langpack/es/rhythmbox/legal.xml looks like a good test case. Here’s what it looks like:

Line three instantiates a File object associated with that file name and then uses the parse() method of XmlSlurper to parse it.

Leave a Comment