Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 基于内部数组项的jq过滤查询_Json_Select_Jq - Fatal编程技术网

Json 基于内部数组项的jq过滤查询

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",

我有一个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"
      }
    ]
  }
]
我想在排除了审阅者
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 )