1
我想使用jq從JSON對象返回多個元素。該數據從AWS CLI查找的到來,這是輸出的只是一小部分:使用jq返回多個元素?
{
"ReservedInstancesOfferings": [{
"OfferingClass": "convertible",
"OfferingType": "No Upfront",
"AvailabilityZone": "ap-southeast-2a",
"InstanceTenancy": "default",
"PricingDetails": [],
"ProductDescription": "Linux/UNIX",
"UsagePrice": 0.0,
"RecurringCharges": [{
"Amount": 0.167,
"Frequency": "Hourly"
}],
"Marketplace": false,
"CurrencyCode": "USD",
"FixedPrice": 0.0,
"Duration": 94608000,
"Scope": "Availability Zone",
"ReservedInstancesOfferingId": "1fc8c02b-bcc0-42b8-82ef-47c6f6d1c1b5",
"InstanceType": "c4.xlarge"
},
{
"OfferingClass": "convertible",
"OfferingType": "No Upfront",
"AvailabilityZone": "ap-southeast-2a",
"InstanceTenancy": "dedicated",
"PricingDetails": [],
"ProductDescription": "Red Hat Enterprise Linux",
"UsagePrice": 0.0,
"RecurringCharges": [{
"Amount": 0.243,
"Frequency": "Hourly"
}],
"Marketplace": false,
"CurrencyCode": "USD",
"FixedPrice": 0.0,
"Duration": 94608000,
"Scope": "Availability Zone",
"ReservedInstancesOfferingId": "24aaceee-f54e-4882-aba3-ce710a5036c9",
"InstanceType": "c4.xlarge"
}
]
}
我想提取字段:
.ReservedInstancesOfferings[].ProductDescription
.ReservedInstancesOfferings[].InstanceType
.ReservedInstancesOfferings[].RecurringCharges[].Amount
我會喜歡輸出像這樣:
"Red Hat Enterprise Linux"
"c4.xlarge"
0.183
正如你可以看到上面我明白如何提取所有元素指標單獨的,但我無法弄清楚如何把它們放在一起來達到預期的輸出。我已經修正了用逗號分隔查詢,但那不提供所需的輸出。
任何幫助將非常感激。
謝謝!
編輯:
哦,哦,我明白了!完整答案如下。男孩哦,男孩jq是強大的!
希望這可以幫助別人:)
您應該添加自己的答案,而不僅僅是編輯問題。 –
是的,我有點興奮:)答案在下面。 –