I have a JSON document similar to the one below and I'm trying to parse it in Groovy. Basically for each school (school information) I want to capture SCHOOL_COUNTRY and other fields. I am trying to use this code below, but it does not return what I need. For each school listed (1000), I want to capture only certain parts, for example:
def parseJSON(long id) { JSONFile fileInstance = JSONFile.get(id) def json = new JsonSlurper().setType(RELAX).parse(new FileReader(fileInstance.filePath)) def schoolInfo = json.SCHOOL_INFO def schoolName = json.SCHOOL_INFO.SCHOOL_NAME schoolInfo.each { render(schoolInfo.SCHOOL_NAME) } }
So, basically for each school, just print out the name of the school. JSON structure:
[{ "SCHOOL_INFO": { "SCHOOL_COUNTRY": "Finland", "SCHOOL NAME": "Findland Higher Learning" }, "LOCATION": { "LONGITUDE": "24.999", "LATITUDE": "61.001" } }]
source share