I need to create a JSON string in my Groovy script which has some elements that are array and some which are not. For example the below..
{
"fleet": {
"admiral":"Preston",
"cruisers": [
{"shipName":"Enterprise"},
{"shipName":"Reliant"}
]
}
}
I found this post but the answers either didn't make sense or didn't apply to my example.
I tried the below in code...
def json = new groovy.json.JsonBuilder()
def fleetStr = json.fleet {
"admiral" "Preston"
cruisers {
{shipName: "[Enterprise]"}, {shipName: "[Reliant]"}
}
}
But it gives an exception...
Ambiguous expression could be either a parameterless closure expression or an isolated open code block