So I'm working with some token filtering at the moment, and have a situation where I need to filter tokens based on the filter condition in C# using the SelectTokens() method, with the catch that if a single value matches the query, I want all objects and/or the root element, for brevity, this is one of the underlying arrays that I want to apply the filtering to:
[
{
"unitPrice": 5
},
{
"unitPrice": 13
}
]
where for example if a single value is above 10, I would want all of the elements in that array, and otherwise no return value, so if I were to use a query like this: $[?($[?(@.unitPrice >= 10)] empty false)]
in my SelectTokens() call, I would expect to get that very same list returned, or an empty array if the comparison value is above 13.
This example works just fine when querying in certain testers such as https://jsonpath.herokuapp.com/ but is seemingly invalid in most other testers, as well as my own C# code, I've attempted to find other alternatives to get this same query functionality, and every time I find a working way to implement this functionality, it turns out to not work within the actual Newtonsoft.Json.Linq.SelectTokens()
method that I'm using.
It seems like whenever I try to use the $
operator within the actual query, it just refuses to work within newtonsoft's implementation of jsonpath, and I can't seem to find people trying to achieve the same thing as me, so I'm just curious if there's an easy way to achieve this that works with newtonsoft's implementation.
This is the closest match for what I'm trying to do, although it's for a single token instead of an array, but it too, only works within specific testers JsonPath: Selecting root level field if satisfies a condition