So I'm working on the bottom 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 get the name
contact that has type S
and returns only the first.
Using jsonpath with this path "$..contacts[?(@.contactType == 'S')].name"
always returns an array of strings because the filter operation always returns the result as an array.
So, I tried "$..contacts[?(@.contactType == 'S')].name[0]"
and "$..contacts[?(@.contactType == 'S')][0].name"
but no luck. This path returns empty results.
So my question is: is there a way to get only the first element when using a filter in jsonpath. I am currently using jayway jsonpath v2.2.0.
source share