Can anyone help to convert a list to list of Maps in Groovy ?
I have a list as below
[war, jar]
and a variable with name "value" = 2.0.0
I want to convert this into a list with maps [["pack": "war", "ver": "2.0.0"],["pack": jar, "ver": "2.0.0"]]
and create a json.
{
"ProjectId": "Projects-16",
"ChannelId": "Channels-41",
"Version": "2.0.1.0-10",
"selectedPackages": [{"pack": "war", "ver": "2.0.0"}, {"pack": jar, "ver": "2.0.0"]}]
}
collectorcollectEntries?["war": "2.0.0", "jar": "2.0.0"]is not the same as[{"war": "2.0.0"}, {"jar": "2.0.0"}]collectand able to form["war": "2.0.0", "jar": "2.0.0"]but i'm not sure how i can convert everything into json.JsonOutputto create JSON?["war": "2.0.0", "jar": "2.0.0"]is not the same as[{"war": "2.0.0"}, {"jar": "2.0.0"}]. I also triedlist.collect { it -> "{$it: ${value}}" }which gives[{jar: 4.0}, {war: 4.0}]. But when i usedJsonBuilderto convert into json, it converts as{ "channelId": "Channels-41", "selectedPackages": [ "war: 2.0.0.","jar:2.0.0" ], "version": "2.0.0.7-10", "projectId": "Projects-16" }