I need to obtain two values from JSON response data returned from a Rest Assured modelled request:
Request public void getCustomerStatuses() {
Response response =
given().header("X-AC-User-ID","test-user").
spec(customerApiSpec).
when().
get("/api/v6/status/" + ref + "/").
then().
assertThat().statusCode(200).extract().jsonPath();
String customerStatus =jsonPath.getString("$.cust[?(@.name=='STATUS_ID')].id");
}
Response:
{
"count": 4,
"cust": [
{
"id": "029384",
"type": "STATUS",
"name": "STATUS_ID"
},
{
"id": "938736",
"type": "RENEWAL",
"name": "RENEWAL_ID"
}
]
}
This throws and java.lang.IllegalArgumentException: Invalid JSON expression:Script1.groovy: 1: Unexpected input: '$.cust[?' @ line 1, column 36. $.cust[?(@.name=='STATUS_ID')].id
What is the correct, best way of obtaining these? I'm aware I can chain extract().response().jsonPath();
off the request but not sure how I can obtain >1 value