【问题标题】:Need james path output需要詹姆斯路径输出
【发布时间】:2019-03-16 10:28:06
【问题描述】:

这是我的 azure cli 输出,带有 -o json 输出。

[
  {
"cloudName": "AzureCloud",
"id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"isDefault": true,
"name": "CSC Number One",
"state": "Enabled",
"tenantId": "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
"user": {
  "name": "user1@gmail.com",
  "type": "user"
}
  },
{
"cloudName": "AzureCloud",
"id": "AAAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAA",
"isDefault": false,
"name": "CSC Number two",
"state": "Enabled",
"tenantId": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
"user": {
  "name": "user1@gmail.com",
  "type": "user"
  }
 }
]

我需要打印唯一的 id 以便我可以运行命令:

az account list --query [].id

这将为我打印所有 id,即 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxAAAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAA

现在我只想在name = "CSC Number One" 处打印id,这意味着结果应该是xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

【问题讨论】:

    标签: json azure azure-cli jmespath


    【解决方案1】:

    问题

    • 构造 Jmespath 查询以返回过滤器表达式的 id 属性
    • 过滤器表达式必须匹配特定名称CSC Number One

    解决方案

    @|[? @.name == `CSC Number One` ]|[*].id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多