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

给你一囗甜甜゛ 提交于 2021-02-11 07:38:59

问题


I have an array of objects similar to the following:

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

How can I select all "id" values for each object containing a tag where "my.key" is "true"?


回答1:


You can use a select with .tags["my.key"] == "true" and get only the id field :

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


来源:https://stackoverflow.com/questions/41369982/how-to-select-a-json-object-where-a-child-value-array-contains-a-certain-propery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!