【发布时间】:2020-08-28 14:15:36
【问题描述】:
{
"status": "DOWN",
"components": {
"ping": {
"status": "UP",
"details": {
"version": "1.0.0",
"description": "dobre application",
"name": "SO-3113"
}
},
"bridge.lock": {
"status": "UP",
"details": {
"description": "test1"
}
},
"Configuration converted": {
"status": "DOWN",
"details": {
"description": "test2"
}
},
"app started": {
"status": "DOWN",
"details": {
"description": "test3"
}
}
}
}
我需要获取具有 DOWN 状态的第一个组件的名称(上述 json 中的“配置转换”)。到目前为止,我只得到了.details.description:
jq -c '.components| .[] | select( .status | contains("DOWN")) .details.description' | head -1
如何获取组件的名称(键)? (“配置转换”)
【问题讨论】:
-
我不清楚你的问题,我在jqplay.org 中使用你的 json 执行了你的查询,它返回给我:“test2”“test3”。你能告诉我你想要的输出是什么吗?
-
需要“配置转换”,因为这首先包含“DOWN”。对不起我的英语不好
标签: jq