在 aws cli 中使用 jq 解析 json

Parse json with jq in aws cli

我需要类似这样的输出

{
  "InstanceType": "c4.xlarge",
  "PrivateIpAddress": "10.54.130.52",
  "PlatformDetails": "Windows BYOL",
  "State":
    "Name": "running"
  }
}

阅读 jq 命令的文档我得到了下一个输出:

aws ec2 describe-instances --instance-ids i-0079e143722b0b8f9 | jq -r '.Reservations[].Instances[] | {InstanceType, PrivateIpAddress, PlatformDetails, State}'
{
  "InstanceType": "c4.xlarge",
  "PrivateIpAddress": "10.54.130.52",
  "PlatformDetails": "Windows BYOL",
  "State": {
    "Code": 16,
    "Name": "running"
  }
}

谁能解释一下怎么做?

此致,

这应该有效:

 aws ec2 describe-instances --instance-ids i-0079e143722b0b8f9 | jq -r '.Reservations[].Instances[] | {InstanceType, PrivateIpAddress, PlatformDetails, State: {Name:.State.Name} }'