JSON QUERY解析提示

时间:2019-01-15 03:34:58

标签: json debugging select jq

只想获取关于如何从AutoScalingGroups中仅获取此信息的专家提示:

  

awseb-e-ASG

实际JSON输出

{
"EnvironmentResources": {
    "EnvironmentName": "MY-APP",
    "AutoScalingGroups": [
        {
            "Name": "awseb-e-ASG"
        }
    ],
    "Triggers": [],
    "LoadBalancers": [
        {
            "Name": "awseb-e-ELB"
        }
    ],
    "Queues": [],
    "Instances": [
        {
            "Id": "i-XXXXXXXXXXXXXXXd"
        }
    ],
    "LaunchConfigurations": [
        {
            "Name": "awseb-e-LAUNCH"
        }
    ]
}
}

我尝试了几个命令,但只能得到这个:

jq -r ".EnvironmentResources.LaunchConfigurations"

[
 {
  "Name": "awseb-e-ASG"
 }
]


jq -r ".EnvironmentResources.LaunchConfigurations.Name"
jq: error: Cannot index array with string

1 个答案:

答案 0 :(得分:0)

awseb-e-ASG在.AutoScalingGroups

因此您可以使用以下过滤器:

.EnvironmentResources.AutoScalingGroups[].Name

调试

通常要注意错误消息:

  

jq:错误:无法使用字符串索引数组

实际上,这是在告诉您.LaunchConfigurations.Name是错误的,因为.LaunchConfigurations是一个数组,因此不能具有字符串值的键。