如何 select 子值数组包含特定 属性 的 json 对象

how to select a json object where a child value array contains a certain propery

我有一个类似于以下的对象数组:

[
  {
    "id": "one",
    "tags": {
      "my.key": "true"
    }
  },
  {
    "id": "two",
  }
]

我如何 select 每个对象的所有 "id" 值包含一个标签,其中 "my.key" 是 "true"?

您可以将 select.tags["my.key"] == "true" 一起使用,并且仅获取 id 字段:

jq '.[] | select(.tags["my.key"] == "true") | .id' data.json