Skip to content
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

Get object from two dimensional array with selection #617

Open
felule opened this issue May 28, 2020 · 6 comments
Open

Get object from two dimensional array with selection #617

felule opened this issue May 28, 2020 · 6 comments

Comments

@felule
Copy link

felule commented May 28, 2020

Hello !

I Have JSON struc like this :
{ "Entreprise": { "Location": [ { "City":"litelTown", "Employee": [ { "Name":"Paul", "Age" : "34" } ] }, { "City":"BigTown", "Employee": [ { "Name":"Arthur", "Age" : "65" }, { "Name":"Pauline", "Age" : "44" }, { "Name":"Elisabeth", "Age" : "34" } ] }, { "City":"MidleTown", "Employee": [ { "Name":"Moahmed", "Age" : "34" }, { "Name":"Yves", "Age" : "38" } ] } ] } }

And i would get something like this :

$..Location.[?(@.Employee[?(@Age== '34')])]
But it's complicated to work with double dimension array

Get the location who have employee who have 34 years old

if any body have an idea ;)

(Sorry for my primitif english)

@hf-kklein
Copy link

This path works for me: $..Location[?(@.Employee[?(@.Age== '34')])]

@felule
Copy link
Author

felule commented May 28, 2020

When i try it on https://jsonpath.herokuapp.com/ seem to work
but if i change age '34' for '44' the result is the same, when the city litelTown and MidelTown should not be there

@hf-kklein
Copy link

The reason is the "..". Since the Entreprise having age 34 entries also hase the age 44 entries they both occur in the result. This is a known shortcoming of this library discussed in #287. Also #559 covers a problem very similar to yours.

@felule
Copy link
Author

felule commented May 28, 2020

Oo thx, i dont understand these issues like this.

@hf-kklein
Copy link

Oo thx, i dont understand these issues like this.

The title of #287 "Filter on children level, return the parent node" is just what you want:
Filter on Employee (=child) level and return the Location (=parent node). The takeaway from the referenced issues is that there are lengthy, boilerplate workarounds within constraints, but no real solution as of today.

@harkue
Copy link

harkue commented Jul 8, 2020

This issue could be close if resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants