I have two ArrayList and I need to print in JSON format. I used the below code to print the ArrayList as JSON string
def a = ['R1','R2']
def b = ['R3','R4']
def json = new groovy.json.JsonBuilder()
json set1: a
println groovy.json.JsonOutput.prettyPrint(json.toString())
json set2: b
println groovy.json.JsonOutput.prettyPrint(json.toString())
Actual output
{
"set1": [
"R1",
"R2"
]
}
{
"set2": [
"R3",
"R4"
]
}
It will be printed as two JSON files, but do I need to print/combine all two sets into a single JSON output?
My expected Output
{
"set1": [
"R1",
"R2"
],
"set2": [
"R3",
"R4"
]
}