I'm trying to retrieve the id of the workflow having "type":"system" using JSON expression
Method:
public static int getSystemWorkflowId(final Map<String, String> cookies) {
return workflow.get(cookies).then().extract().jsonPath().getInt("$..workflows[?(@.type =='system')].id");
}
Payload
{
"workflows": [
{
"id": 1,
"name": "Recruitment workflow",
"type": "system",
"options": [
],
"active": 1
},
{
"id": 3,
"name": "TestWorkflow",
"options": [
],
"active": 1
}
]
}
Error:
java.lang.IllegalArgumentException: Invalid JSON expression: Script1.groovy: 1: Unexpected input: '[' @ line 1, column 39. $..workflows[?(@.type =='system')].id
I've tested the expression in an online evaluator and it seems to work...enter image description here
Thanks!
JsonPath in Rest-Assured is not JsonPath Jayway, please don't get confused.
JsonPath in Rest-Assured utilizes GPath groovy to find and extract value.
The correct expression would be:
.getInt("workflows.find {it.type == 'system'}.id")