I'm trying to use JSONPath (Jayway implementation), to get objects that contains a values array, that contains at least 1 non empty value. This is a simplified data I get from some service:
[
{
"feature" : "city",
"values" : [
{
"value" : "cba"
},
{},
{
"value" : "abc"
}
]
},
{
"feature" : "country",
"values" : [
{},
{}
]
}
]
I've dozens of crazy approaches.
$.[?(@..value)]
but this filters nothing I can still see both objects instead of only one.
values
array but it doesn't work either, and returns an empty list:$.[?(@.values[?(@.value)].length()>1)]
I'm trying to work it out using online evaluator from jsonpath.herokuapp.com I've been searching a lot and it seems that getting the length of the filtered array isn't possible, but the first approach looks like something that should work. Any ideas?
With Jayway-JSONPath you can use the empty Filter Operator
Filter the object
$.[?(@..value empty false)]