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

How to return a child node and a parent node attribute in the same query JMES Path for JSON object #67

Open
bosskay972 opened this issue Jun 1, 2019 · 1 comment

Comments

@bosskay972
Copy link

bosskay972 commented Jun 1, 2019

Considert we have this JSON:

{  
   "A":[  
      {  
         "AT":"text"
      },
      {  
         "AT":"text2"
      }
   ],
   "B":[  
      {  
         "name":"text",
         "power":10
      },
      {  
         "name":"text1",
         "power":20
      },
      {  
         "name":"text2",
         "power":40
      }
   ]
}

I want to return "AT" and the power corresponding to "AT", so I don't want to return "text1" but just [["text",10],["text2",40]]. This query [A[*].AT,B[*].power] return this: [["text","text2"],[10,20,40]]. So it's not exactly what I want because I don't want the extra value: 20 from "text1". I found this portion of code root[*].B[?contains(['text','text2'],name)].[name,power][][] it return ["text",10,"text2",40] this is the good result BUT the query isn't dynamics, because in the contain I have this ['text','text2'] and I want to replace this portion of code with a nested query if it's possible, so, how can I do that ?
How can I fix that ?

@chadselph
Copy link
Contributor

I think you need a custom function

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

2 participants