Reputation: 8431
Given that i have the below json:
{
"id": "images",
"type": "collection",
"href": "https://api.ionos.com/cloudapi/v5/images",
"items": [
{
"id": "2bdfc61e-1ff7-11ea-af1c-525400f64d8d",
"type": "image",
"href": "https://api.ionos.com/cloudapi/v5/images/2bdfc61e-1ff7-11ea-af1c-525400f64d8d",
"metadata": {
"etag": "b1a133b9ac038de9157572bbc3491898",
"createdDate": "2019-12-16T11:28:24Z",
"createdBy": "System",
"createdByUserId": "System",
"lastModifiedDate": "2019-12-16T11:28:24Z",
"lastModifiedBy": "System",
"lastModifiedByUserId": "System",
"state": "AVAILABLE"
},
"properties": {
"name": "windows-2008-r2-server-2019-12",
"description": "",
"location": "gb/lhr",
"size": 18,
"cpuHotPlug": true,
"cpuHotUnplug": false,
"ramHotPlug": false,
"ramHotUnplug": false,
"nicHotPlug": true,
"nicHotUnplug": true,
"discVirtioHotPlug": true,
"discVirtioHotUnplug": false,
"discScsiHotPlug": false,
"discScsiHotUnplug": false,
"licenceType": "WINDOWS",
"imageType": "HDD",
"imageAliases": [
"windows:2008r2"
],
"public": true
}
},
{
"id": "d65c184b-cd78-11e9-b88c-525400f64d8d",
"type": "image",
"href": "https://api.ionos.com/cloudapi/v5/images/d65c184b-cd78-11e9-b88c-525400f64d8d",
"metadata": {
"etag": "f3f490ba129dbb56b4dd0f97870240b8",
"createdDate": "2019-09-02T11:57:28Z",
"createdBy": "System",
"createdByUserId": "System",
"lastModifiedDate": "2019-09-02T11:57:28Z",
"lastModifiedBy": "System",
"lastModifiedByUserId": "System",
"state": "AVAILABLE"
},
"properties": {
"name": "ubuntu-16.04.6-server-amd64.iso",
"description": "",
"location": "gb/lhr",
"size": 0.86,
"cpuHotPlug": true,
"cpuHotUnplug": false,
"ramHotPlug": true,
"ramHotUnplug": false,
"nicHotPlug": true,
"nicHotUnplug": true,
"discVirtioHotPlug": true,
"discVirtioHotUnplug": true,
"discScsiHotPlug": false,
"discScsiHotUnplug": false,
"licenceType": "LINUX",
"imageType": "HDD",
"imageAliases": [
"ubuntu:16.04_iso"
],
"public": true
}
},
]
}
I need to find the first id
among items
which its properties
feature, has "licenceType": "LINUX"
, and "imageType": "HDD"
.
Here is the code that i tried :
$.items[?(@.properties.imageType=="HDD"
@.properties.licenceType=="LINUX" )].id
In my example, it should return d65c184b-cd78-11e9-b88c-525400f64d8d
But, it does not give me anything.
Upvotes: 0
Views: 47
Reputation: 2143
you have to AND
both queries so this should work
$..items[?(@.properties.imageType=="HDD" && @.properties.licenceType=="LINUX" )].id
if first element is required then
$..items[0].id
Upvotes: 1