I want to generate multiple json blocks and to merge them in one to pass in a request. Below is the sample block,
{
"roomId": "1429293",
"daysCount": "9173",
"a": "F",
"x": "0",
"t": "0",
"y": "-",
"l": "0"
}
But there are some conditions for each block,
I have tried doing it with JSR post processor with groovy code but no success. Can someone please help with the code. Thanks in advance.
As far as I got your requirement it would be something like this:
def payload = []
1.upto(vars.get('foo_matchNr') as int, { roomId ->
def startValue = 9173
1.upto(300, block -> {
def entry = [roomId: vars.get('foo_' + roomId), daysCount: startValue as String, a: "F", x: "0", t: "0", y: "-", l: "0"]
startValue = startValue + 1
payload.add(entry)
})
})
vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())
More information: