On https://jsonpath.com I have below example, using expression
$.phoneNumbers[?(@.id < 3)].number
on below JSON object.
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-1111",
"id": 1
},
{
"type" : "home",
"number": "0123-4567-2222",
"id": 2
},
{
"type" : "home",
"number": "0123-4567-3333",
"id": 3
}
]
}
Result is
[
"0123-4567-1111",
"0123-4567-2222"
]
Question
I only want the first string "0123-4567-1111", but appending [0] to my expression does not work. Expression $.phoneNumbers[?(@.id < 3)].number[0] gives result ["0","0"]. How can I get the first returned string?