Arrays 如何使用jq从json文件中选择另一个匹配的值
我一直在努力处理json的东西。我想找到运行状态的href。我如何使用Arrays 如何使用jq从json文件中选择另一个匹配的值,arrays,json,bash,select,jq,Arrays,Json,Bash,Select,Jq,我一直在努力处理json的东西。我想找到运行状态的href。我如何使用jq或其他类似bash的样式来实现这一点 这是我的卷曲输出: { "relations": { "total": 9, "link": [ { "href": "https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/", "rel": "up" },
jq
或其他类似bash
的样式来实现这一点
这是我的卷曲输出:
{
"relations": {
"total": 9,
"link": [
{
"href": "https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/",
"rel": "up"
},
{
"href": "https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/executions/",
"rel": "add"
},
{
"attributes": [
{
"value": "8f961082-cccc-412f-9244-16ba5b949dbe",
"name": "id"
},
{
"value": "2019-09-28T17:20:40.691-01:00",
"name": "startDate"
},
{
"value": "2019-09-28T17:20:43.949-01:00",
"name": "endDate"
},
{
"value": "completed",
"name": "state"
},
{
"value": "test",
"name": "name"
},
{
"name": "currentItemDisplayName"
}
],
"href": "https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/executions/8f961082-cccc-412f-9244-16ba5b949dbe/",
"rel": "down"
},
{
"attributes": [
{
"value": "b28832cb-2a97-4ec8-848f-35fec95eb867",
"name": "id"
},
{
"value": "2019-09-28T17:21:04.643-01:00",
"name": "startDate"
},
{
"value": "running",
"name": "state"
},
{
"value": "test",
"name": "name"
},
{
"name": "currentItemDisplayName"
}
],
"href": "https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/executions/b28832cb-2a97-4ec8-848f-35fec95eb867/",
"rel": "down"
}
}
如果我与示例交谈,我想通过运行key来查找href key。修复示例JSON后,以下jq查询:
.relations.link[]
| select( has("attributes") )
| select( any(.attributes[]; .value=="running" and .name == "state") )
| .href
产生:
"https://vro:8281/vco/api/workflows/6433f56f-13b7-46a7-a9ec-a3e38c7ff69d/executions/b28832cb-2a97-4ec8-848f-35fec95eb867/"
两条管线(即一条管线)
请显示所需的输出。
运行状态的href
-这意味着什么?解析错误:对象必须由第67行第1列的键:值对组成
.relations.link[]
| select(any(.attributes[]?; .value=="running" and .name == "state")).href