【发布时间】:2021-03-15 13:58:21
【问题描述】:
我正在尝试使用 JQ 在这种 json 中返回父级:
{
"all" : {
"text": "a",
"children": [
{
"text": "aa",
"children": []
},
{
"text": "ab",
"children": []
},
{
"text": "ac",
"children": [
{
"text": "aca",
"children": []
},
{
"text": "acb",
"children": []
},
{
"text": "acc",
"children": [
{
"text": "acca",
"children": []
}
]
}
]
}
]
}
}
目标是检索元素的父文本。 例如:
- 搜索 acca --> acc
- 正在搜索 acc --> ac
此代码不起作用:
.all | .children[] as $parent | select(.children[].text == "acca" ) | $parent.text
有人可以帮助我吗? 谢谢! :)
【问题讨论】:
标签: json jq parent recursive-datastructures