Reputation: 394
How can I use JMESPath
in Python
to extract the array [["S", "2313711"], ["S", "15366545"]]
from the data below:
data = {
"categories": [
{
"sport": "S",
"children": [
{"id": "2313711"},
{"id": "15366545"}
]
}
]
}
Please note that the length of the children array may vary.
So far, I tried:
jmespath.search("categories[][ [ sport, children[].id] ][]", data)
# output: [['S', ['2313711', '15366545']]]
This is not what I want, as it groups all child IDs under one list instead of generating separate lists for each child ID and the corresponding sport value.
Upvotes: 0
Views: 24