jmespath / jmespath/jmespath.site
How to return a child node and a parent node attribute in the same query JMES Path for JSON object
- Dominant language
- Makefile
- Stars
- 61
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
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 ?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.