Reputation: 1
Im trying to get JSONPath expression to filter my JSON and get whole sport object using value of child array.
I have following JSON:
[{
"name": "Soccer",
"regions": [{
"name": "Australia",
"leagues": [{
"name": "Australia league",
"inplay": 5,
}
]
}
]
}, {
"name": "Tennis",
"regions": [{
"name": "Germany",
"leagues": [{
"name": "Germany league",
"inplay": 0,
}
]
}
]
}
]
I need to get whole sport object where "inplay == 0" using JsonPath expression.
Result should look like that:
{
"name": "Tennis",
"regions": [{
"name": "Germany",
"leagues": [{
"name": "Germany league",
"inplay": 0,
}
]
}
]
}
Regions and Leagues count can be > 1
Therefore $[?(@.regions[0].leagues[0].inplay == 0)]
is not suitable
Tried $[?(@.regions[*].leagues[*].inplay == 0)]
but it doesnt work
Upvotes: 0
Views: 1820
Reputation: 19000
Since this is not directly supported (as of now) in JayWay JSONPath we leverage contains
as a workaround:
$[?(@.regions..inplay contains '0')]
Note: It may look like contains would work similar to a 'like' operator or instr
function but this is not the case here. If the inplay
value contains a 0, e.g. 10
it would not pull the record (according to my tests;)
Upvotes: 1
Reputation: 5917
This works for me
$[?(@.regions[0].leagues[0].inplay == 0)]
Upvotes: 0