需要詹姆斯路径输出

时间:2019-03-16 10:28:07

标签: json jmespath

这是我来自azure cli的输出,输出为await fixture.whenStable();

-o json

我需要打印唯一的ID,这样我才能运行命令:

[
  {
"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 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

现在,我想仅在AAAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAA处打印ID,这意味着结果应该是name = "CSC Number One"

1 个答案:

答案 0 :(得分:0)

问题

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

解决方案

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