如何在子值数组包含某个属性的情况下选择json对象 [英] how to select a json object where a child value array contains a certain propery

查看:56
本文介绍了如何在子值数组包含某个属性的情况下选择json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an array of objects similar to the following:

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

如何为包含"my.key"为"true"的标签的每个对象选择所有"id"值?

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

推荐答案

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

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

这篇关于如何在子值数组包含某个属性的情况下选择json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆