How can I browse a JSON with Groovy ? How to use bodyAsObject ?

1
+1
-1

Hi

I have JSON data like :
{
"Id":12,
"Title":"194",
"StartDate": "2018-08-30T00:00:00",
"EndDate": "2018-09-07T00:00:00"
}
{
"Id":13,
"Title":"195",
"StartDate": "2018-06-30T00:00:00",
"EndDate": "2018-10-07T00:00:00"
}

I used a connector REST GET but I only got the full API so I use bodyAsString.split() to get the StartDate in a variable or the Title in an other variable.
But how can I use bodyAsObject to get the list of all StartDates and the list of all Titles ?

Thank You

1 answer

1
0
-1
This one is the BEST answer!

You can use "groovy.json.JsonSlurper" library

def slurper = new JsonSlurper()

def oJson = slurper.parseText(stringdata)

loger.info("date: "+ oJson.StartDate)

I hope this helps to someone
Notifications