In my Groovy code, I've got two variables declared:
results
is an array of maps. It contains a list of rows returned from a SQL query.
overall
is a map. It represents a single row of a separate SQL query.
I want to combine these two variables into one and output the whole thing as JSON. In the end, I want it to look something like this:
{"data":[{"results":"array"}],"overall":{"overall":"map"}}
Here's the code I'm trying to use, but it doesn't work:
def json = new groovy.json.JsonBuilder()
def finalJSON = json {
data results
overall overall
}
return json.toString()
But this doesn't work... it throws the following exception:
groovy.lang.MissingPropertyException: No such property: call for class: groovy.sql.GroovyRowResult
I can verify that both variables results
and overall
have the correct data in them. I guess I'm just not understanding the syntax for JsonBuilder.