JSONPath scripts not executing correctly for objects
See original GitHub issueUsing scripts to query objects does not seem to work properly (although it does work properly for arrays). Given an example JSON:
{
"A": {
},
"B": {
"B1": 1,
"B2": 2
},
"C": {
"C1": {
"C11": true
},
"C2": 2
}
}
Parsing this into a JObject
and then executing SelectTokens
with a script does not yield the correct results
Running $[?(@)]
from the root returns the all of the properties in the object, as expected
Running $[?(@.B1)]
or $[?(@.B1 == 1)]
should return the B property, but does not actually
If I use the recursive operator, $[?(@..B1)]
then the B node is returned, which makes me think that the child operator is not working for a script inside an object.
Additionally, the value of the properties cannot be accessed from within the script.
If I run $[?(@ == 1)]
inside the B object, I’d like to be returned the B1 token (or the token for its value) but it actually returns nothing.
The behavior that I’m referring to is based on the interpretation of the JSONPath spec expressions as well as the behavior of some JSONPath evaluators such as this and this) The examples that I mentioned above using JSON.Net can he found here.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:10 (2 by maintainers)
That’s a real bummer. Just ran into this issue myself and was surprised to see it’s been left with no attention for almost three years now 😦
The spec says that “expressions of the underlying script language can be used as an alternative to explicit names or indices”, which makes me think that filter expressions can also be used instead of names.