Let's say I have this JSON:
{
"toplevel": [
{
"testval": "accept",
"number": 1
},
{
"testval": "reject",
"number": 2
},
{
"testval": "accept",
"number": 3
},
{
"testval": "reject",
"number": 4
}
]
}
I would like to get the value of "number" from the last member of "toplevel" which has a "testval" of "accept".
$.toplevel[?(@.testval == 'accept')].number
gets me this, as you'd expect:
[
1,
3
]
But what I want ultimately is to get that "3" as a result.
Since that seems to produce an array, I was hoping something like this would work:
$.toplevel[?(@.testval == 'accept')][-1].number
or even this:
$.toplevel[?(@.testval == 'accept')].number[-1]
But those don't match anything.
Unfortunately I'm limited to pure JSONPath. I'm entering a JSONPath string into a config file, so there's no ability to process the results, or do multiple JSONPath queries.
Any ideas?