Я пытаюсь выбрать учетные объекты, только если в них существует ключ credhub-ref
из следующего JSON:
{
"total_results": 23,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"entity": {
"credentials": {},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2018-10-15T19:13:57Z",
"created_at": "2018-10-15T19:13:57Z"
},
"app_url": "/v2/3"
}
},
{
"entity": {
"app_guid": "sd",
"service_instance_guid": "sd",
"credentials": {
"hostname": "w",
"port": 3306
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2018-10-15T19:24:06Z",
"created_at": "2018-10-15T19:24:06Z"
},
"app_url": "/v2/3"
}
},
{
"entity": {
"credentials": {
"credhub-ref": "ref3"
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-19T20:07:27Z",
"created_at": "2019-03-19T20:07:27Z"
},
"app_url": "/v2/45"
}
},
{
"entity": {
"credentials": {
"credhub-ref": "ref4"
},
"binding_options": {},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"volume_mounts": [],
"name": null,
"last_operation": {
"type": "create",
"state": "succeeded",
"description": "",
"updated_at": "2019-03-19T20:07:27Z",
"created_at": "2019-03-19T20:07:27Z"
},
"app_url": "/v2/45"
}
}
]
}
Когда я использую cat my_bindings_test2.json | jq '.resources[] | .entity.credentials'
, я получаю:
{}
{
"hostname": "w",
"port": 3306
}
{
"credhub-ref": "ref3"
}
{
"credhub-ref": "ref4"
}
Используя JQ, как бы я получил следующий результат?
{
"credhub-ref": "ref3"
}
{
"credhub-ref": "ref4"
}