jQuery-提取最后一个元素(无数组)

时间:2019-10-29 23:06:47

标签: json jq

如何提取最后一个元素-“日期”?

预期输出=“ 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"
}

1 个答案:

答案 0 :(得分:1)

使用last,例如:

last(.snapshots[] | select(.state == "SUCCESS"))
| .snapshot