【问题标题】:select key names base on subject values根据主题值选择键名
【发布时间】:2021-06-01 19:12:31
【问题描述】:

Hashicorp Vault 为我提供以下 JSON:

{
  "somekey1/": {
    "accessor": "generic_123456,
    "config": {
      "default_lease_ttl": 0,
      "force_no_cache": false,
      "max_lease_ttl": 0
    },
    "description": "",
    "external_entropy_access": false,
    "local": false,
    "options": {},
    "seal_wrap": false,
    "type": "generic",
    "uuid": "1111111-2222-3333-4444-55555555555"
  },
  "somekey2/": {
    "accessor": "aws_123456",
    "config": {
      "default_lease_ttl": 3600,
      "force_no_cache": false,
      "max_lease_ttl": 86400
    },
    "description": "",
    "external_entropy_access": false,
    "local": false,
    "options": null,
    "seal_wrap": false,
    "type": "aws",
    "uuid": "1111111-2222-3333-4444-55555555555"
  },
  "somekey3/": {
    "accessor": "generic_1234567",
    "config": {
      "default_lease_ttl": 0,
      "force_no_cache": false,
      "max_lease_ttl": 0
    },
    "description": "",
    "external_entropy_access": false,
    "local": false,
    "options": {},
    "seal_wrap": false,
    "type": "generic",
    "uuid": "1111111-2222-3333-4444-55555555555"
  }
}

我想确定哪些顶级键具有子对象 K/V .type="generic"。 在这种情况下,“somekey1/”和“somekey3/”

或带有子对象 K/V .type="aws" 的 "somekey2/"。

这可以用JQ来完成吗?

【问题讨论】:

    标签: json select key jq


    【解决方案1】:

    在这种情况下,我使用以下内容:

    jq 'to_entries[] | select (.value.type == "generic") | .key' vault.json
    

    产生:

    "somekey1/"
    "somekey3/"
    

    这正是我想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 2020-09-28
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多