Json 基于内部数组项的jq过滤查询
我有一个json作为Json 基于内部数组项的jq过滤查询,json,select,jq,Json,Select,Jq,我有一个json作为 [ { "id":1, "author": "hippy", "reviewers": [ { "name": "hippy", "status": "ok" }, { "name": "other", "status": "ok" } ] }, { "id":2, "author": "hippy",
[
{
"id":1,
"author": "hippy",
"reviewers": [
{
"name": "hippy",
"status": "ok"
},
{
"name": "other",
"status": "ok"
}
]
},
{
"id":2,
"author": "hippy",
"reviewers": [
{
"name": "hippy",
"status": "ok"
},
{
"name": "build",
"status": "ok"
}
]
},
{
"id":3,
"author": "hippy",
"reviewers": [
{
"name": "hippy",
"status": "ok"
}
]
},
{
"id":4,
"author": "other",
"reviewers": [
{
"name": "hippy",
"status": "ok"
}
]
}
]
我想在排除了审阅者build
之后,获得reviewer
与author
相同的项目
i、 e.我想获得id为s2、3的项目
我能走这么远
.[]
| select(
.author as $author
| {reviewers}
| .[]
| map(.name)
| select(.[] == $author)
)
但id为1的项目为假阳性,我也想将其过滤掉 从描述和您只想要这两件物品的事实来看,我相信这就是您想要的:
.[]
| select( .author as $author
| .reviewers
| map(select(.name != "build")) # ignore "build"
| length==1 and .[0].name == $author )