So I'm working on the below json:
{
"id": "",
"owner": "some dude",
"metaData": {
"request": {
"ref": null,
"contacts":[
{
"email": null,
"name": null,
"contactType": "R"
},
{
"email": null,
"name": "Dante",
"contactType": "S"
}
]
}
}
}
I want to retrieve the name
of contact has type S
and only the first one that returned.
Using jsonpath with this path "$..contacts[?(@.contactType == 'S')].name"
always return an array of string because a filter operation always return result as an array.
So I tried "$..contacts[?(@.contactType == 'S')].name[0]"
and "$..contacts[?(@.contactType == 'S')][0].name"
but no luck. Those path returns empty results.
So my question is, is there any way to get only first element when using filter in jsonpath. I'm currently using jayway jsonpath v2.2.0.