我有一个json
[
{
"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"
}
]
}
]
我想在排除评论者reviewer
后获取author
与build
相同的项目。
即。我希望获得id
s 2,3的项目。
我能够到目前为止
.[]
| select(
.author as $author
| {reviewers}
| .[]
| map(.name)
| select(.[] == $author)
)
但是id
1的项目是误报,我也想过滤掉它。
答案 0 :(得分:2)
从描述和您只想要这两个项目的事实来看,我相信这正是您所寻找的:
.[]
| select( .author as $author
| .reviewers
| map(select(.name != "build")) # ignore "build"
| length==1 and .[0].name == $author )