Hello, I am trying to build JSON from two fields. Say, I have a list of object(party), and I only need to pass 2 items as JSON pair.
def list = getMyList() //it contains 2 party objects
partyTo = array {
for (i in list) {
x partyId: i.id
y partyName: i.toString()
}
}
The JSON string is
{"partyTo":[
{"partyId":12},
{"partyName":"Ar"},
{"partyId":9},
{"partyName":"Sr"}
]
}
when I extract it at the client, it is treated as 4 objects. I wanted as 2 objects, with the below format.
{"partyTo":[ {"partyId":12 , "partyName":"Ar"},
{"partyId":9 , "partyName":"Sr"}
]
}
I'm getting 4 objects, probably because I use an array to build JSON. I'm new to groovy and JSON, so not sure about the right syntax combinations. Any help highly appreciated. thanks.