-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter on children level, return the parent node #287
Comments
Works fine for me, though your jsonpath has some errors. This one |
Hi @tjakopanec Thanks for pointing it out. I have fixed my typo. However, I don't see it working as my expectation. The filter does not work as it will return everything including those books whose authors' name were not "Waugh". Would you give it a try? |
I've just tried it again and it works as I expect it to run. Just to avoid any confusion, this is my input: This is the jsonPath I use: This is the result I'm getting: Is this the result you would expect? |
Hi @tjakopanec thanks for the updates.
The JsonPath I am using is the same as yours: Thank you. |
Sorry for the late reply. Yeah, you are right. I've tried it on some of my examples and it's not working correctly. I guess the author of the library should have a look then. |
+1 Seeing the same issue. This is stopping us us writing any jsonpath queries containing nested filters. |
Any update on how to fetch parent when filter is applied on child node |
Hi, has there been any update on this issue? |
Really looking forward to have this issue resolved for the Jayway implementation. |
which is not supported by the current version of jayway json-path refer json-path/JsonPath#287
This functionality is needed in our project. Any updates? |
really needed feature to extract parent data from filtering nested arrays |
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
just found a workaround, now I am using the library |
+1 |
Project appears to be dormant... |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
This works for me if authors was a map and not a list |
|
Is there any any update on this one, this would be really helpful. |
I found this works as expected with Json.Net, at least with version 12.0.3 My query I can't post the data here without a lot of heavy editing but the query is the same nested array query to return the parent purchase objects where there is a payment with type CASH. |
Having same issue but perhaps this behaviour is as per jsonpath spec. If authors is an array, the parent node of a filter for, say, The Currently, to get the desired result, I have to first do a |
As a workaround (it works on https://jsonpath.herokuapp.com/ but not other simulators): JsonPath : $.[?(@.c[*].d contains "d3" )]['a', 'b'] Input : It brings the correct result : [ |
Building off of the previous answer from ArtVandalayy - using the modified book store example input (with authors as a complex object):
Using this path, which filters on authors with last name given: Or alternate path if deepscan operator '..' is not supported: We get this correct output according to https://jsonpath.herokuapp.com/ ver 2.3.0 - 2017-07-04 14:54:00
|
Hello Everyone, I have a similar requirement. { where I need the value of the entries right under sore like these values "10162022" "10162021" from above code. appreciate any suggestions. |
It's may not be a bug. @ArtVandalayy makes a good point. As stated in documentation, filter expression must evaluate to a boolean value. The problem with previous solution
@ArtVandalayy's solution converts main expression to the boolean;
If we convert it for the example, it will be something like
Yeah, it works, but there are other options. Better solutionWe can check for an empty. $.store.book[?(@.authors[?(@.lastName == 'Waugh')] empty false)] When filter expression checks for an And, there are more filter operators to use: https://github.com/json-path/JsonPath#filter-operators |
@tolpp, @dengmingcong, @thadguidry, @VerkhovtsovPavel I tried It does not work. JsonPath fails as - "jsonPath: Unexpected token '?': _$v.authors[?($_v.lastName == 'Waugh'" NewtonSoft fails as - "'Could not read query operator.'" Am I missing anything? |
I think jsonpath[.]com is based on different JsonPath implementation.(https://github.com/ashphy/jsonpath-online-evaluator) It still works on https[:/]/www.javainuse[.]com/jsonpath |
@tolpp Would you have any idea where I can see how nested queries can be written for newtonsoft or how this query should be changed to get same results in newtonsoft please? |
I wonder if it is possible to filter on the child level complex objects (not simple string), and retrieve those parent nodes whose children matches the predicts.
Taking the bookstore example from Jayway's github project: https://github.com/jayway/JsonPath#path-examples.
If I would change "author" to a more complex object like following:
With that, how can I get back "all books that were written by someone with last name of 'Waugh' " ?
I have tried with Json Evaluator (http://jsonpath.herokuapp.com/) to use something like
$.store.book[?(@.authors[?(@.lastName == 'Waugh')])]
, but it seems like the filter doesn't work. I am guessing Jayway does not allow a nested predicates. If that's the case, would there be any workaround for this?The text was updated successfully, but these errors were encountered: