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

return parent element by querying the child nodes #394

Open
ShujaathKhan opened this issue Sep 24, 2017 · 3 comments
Open

return parent element by querying the child nodes #394

ShujaathKhan opened this issue Sep 24, 2017 · 3 comments
Labels

Comments

@ShujaathKhan
Copy link

How can we return the parent nodes by querying the child nodes
Here goes the query which I'm trying to implement

$..holidays[].holidays_by_month[].institution_list[?(@.insitution=='inst1')]
which works fine and returns only the child elements what if I want to get the parent elements
which i've tested here http://jsonpath.com/

Here goes JSON Output

[
  {
    "insitution": "MaGE",
    "location": [
      "Bangalore",
      "Chennai",
      "Delhi",
      "Mumbai",
      "Hyderabad",
      "Kolkata"
    ]
  },
  {
    "insitution": "MaGE",
    "location": [
      "Bangalore",
      "Chennai",
      "Delhi",
      "Mumbai",
      "Hyderabad",
      "Kolkata"
    ]
  }
]

Input Json as below

{
  "holidays": [
    {
      "month": "January",
      "month_id": 0,
      "holidays_by_month": [
        {
          "date": "2017-01-01",
          "name": "New Year",
          "institution_list": [
            {
              "insitution": "inst1",
              "location": [
                "Bangalore",
                "Chennai",
                "Delhi",
                "Mumbai",
                "Hyderabad",
                "Kolkata"
              ]
            },
            {
              "insitution": "inst2",
              "location": [
                "Bangalore",
                "Chennai",
                "Delhi",
                "Mumbai",
                "Hyderabad",
                "Kolkata"
              ]
            }
          ]
        },
        {
          "date": "2017-01-26",
          "name": "Republic Day",
          "institution_list": [
            {
              "insitution": "inst1",
              "location": [
                "Bangalore",
                "Chennai",
                "Delhi",
                "Mumbai",
                "Hyderabad",
                "Kolkata"
              ]
            }
          ]
        }
      ]
    }
    
  ]
}
@demlik
Copy link

demlik commented Sep 26, 2017

I am also stuck trying to do something similar. Here is some JSON:

[ {
"id" : "application_1503554907321_4299",
"name" : "Ingest",
"attempts" : [ {
"startTime" : "2017-09-26T09:19:17.212GMT",
"endTime" : "2017-09-26T09:54:25.588GMT",
"sparkUser" : "test",
"completed" : true
} ]
}]

I would like to extract id, name, attempts[0].startTime, attempts[0].endTime to produce something like:

{
"id" : "application_1503554907321_4299",
"name" : "Ingest",
"startTime" : "2017-09-26T09:19:17.212GMT",
"endTime" : "2017-09-26T09:54:25.588GMT"
}

How can I achieve this?

@kallestenflo
Copy link
Contributor

This is currently not supported.

@zengmmm00
Copy link
Contributor

Hi. I would love to work on this feature.

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

No branches or pull requests

4 participants