如何提取最后一个元素-“日期”?
预期输出=“ 2019_10_29_12_01_01”
$ cat snapshots.json | jq '.snapshots[] | select (.state == "SUCCESS") | {date: .snapshot}'
{
"date": "2019_10_21_12_01_01"
}
{
"date": "2019_10_28_00_01_01"
}
{
"date": "2019_10_29_12_01_01"
}
答案 0 :(得分:1)
使用last
,例如:
last(.snapshots[] | select(.state == "SUCCESS"))
| .snapshot