Reputation: 1433
I am trying to pass json
response to Groovy 'jsonString' parameter. It is correctly working when I pass json manually in code. But my response is dynamic and i need to pass at runtime.
import groovy.json.JsonSlurper
String jsonString = context.expand('${REST SearchRooms#Response}')
JsonSlurper jsonSlurper = new JsonSlurper()
Map convertedJSONMap = jsonSlurper.parseText(jsonString)
if(convertedJSONMap."RoomSearchResult")
{
log.info "ResourceItemID : " + convertedJSONMap."RoomSearchResult"[0]."ResourceItemID"
}
My json response look like this :
{
"Success": true,
"TotalRecords": 2,
"RoomSearchResult": [
{
"ResourceItemID": 2290,
"Name": "Room 23 (L02)",
"LocationId": 7,
"GroupID": 518,
"FloorID": 2,
"DefaultCapacity": 4,
"CanBeBooked": true
},
{
"ResourceItemID": 2063,
"Name": "Room 15 (L10)",
"LocationId": 7,
"GroupID": 518,
"FloorID": 10,
"DefaultCapacity": 8,
"CanBeBooked": true
}
],
"Error": {
"ErrorCode": 0,
"ErrorDescription": ""
}
}
Error : The JSON input text should neither be null nor empty.
I am new to groovy. Please suggest how to do it.
Upvotes: 2
Views: 1158
Reputation: 21389
You have trivial error.
Chage below line
From:
String jsonString = context.expand('${REST SearchRooms#Response}')
To:
String jsonString = context.expand('${SearchRooms#Response}')
Upvotes: 1