我有以下JSON:使用JQ選擇對象不包含嵌套對象
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Node",
"metadata": {
"annotations": {
"node.alpha.kubernetes.io/ttl": "0",
"volumes.kubernetes.io/controller-managed-attach-detach": "true"
},
"creationTimestamp": "2017-09-14T11:53:07Z",
"labels": {
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
"kubernetes.io/hostname": "msl-kub01.int.na.myapp.com",
"node-role.kubernetes.io/master": ""
},
"name": "msl-kub01.int.na.myapp.com",
"namespace": "",
"resourceVersion": "123154",
"selfLink": "/api/v1/nodes/msl-kub01.int.na.myapp.com",
"uid": "45e3b430-9943-11e7-bf0b-fa163e6604fc"
},
"spec": {
"externalID": "msl-kub01.int.na.myapp.com",
"taints": [
{
"effect": "NoSchedule",
"key": "node-role.kubernetes.io/master",
"timeAdded": null
}
]
}
},
{
"apiVersion": "v1",
"kind": "Node",
"metadata": {
"annotations": {
"node.alpha.kubernetes.io/ttl": "0",
"volumes.kubernetes.io/controller-managed-attach-detach": "true"
},
"creationTimestamp": "2017-09-14T12:05:42Z",
"labels": {
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
"kubernetes.io/hostname": "msl-kub02.int.na.myapp.com"
},
"name": "msl-kub02.int.na.myapp.com",
"namespace": "",
"resourceVersion": "123156",
"selfLink": "/api/v1/nodes/msl-kub02.int.na.myapp.com",
"uid": "084f439e-9945-11e7-bf0b-fa163e6604fc"
},
"spec": {
"externalID": "msl-kub02.int.na.myapp.com"
}
}
],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}}
,我需要選擇不具有「項目」列表中的所有條目「 spec.taints []效果==」 。NoSchedule」
事情是污點名單和效果的關鍵在於存在不是在源JSON強制性的,所以我不能做:
select (.spec.taints[].effect != "NoSchedule")
我希望使用這樣的:
select (has(".spec.taints[].effect") | not)
但這是不允許的。
Thx提示。
發佈最終預期結果 – RomanPerekhrest