使用 jq 从跨多个对象的键返回单个最小日期值
Returning a single minimum date value from a key across multiple objects with jq
我有一组对象如下,我正试图从所有对象中获取一个日期值。
期望的输出是:
"2014-12-16T08:59:08.000+0100"
数据集为:
[
{
"key": "AB-12345",
"type": "Fault",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad fault",
"closedDate": null,
"flag": null
},
{
"key": "AB-12346",
"type": "Bug",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad bug",
"closedDate": "2014-12-16T08:59:08.000+0100",
"flag": null
},
{
"key": "AB-12347",
"type": "Feature",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad feature",
"closedDate": "2014-12-17T08:27:07.000+0100",
"flag": null
}
]
我已经成功地使用了:
.[] | {"closedDate": .closedDate} | select(.closedDate > 0)
哪个会得到我:
{
"closedDate": "2014-12-16T08:59:08.000+0100"
}
{
"closedDate": "2014-12-17T08:27:07.000+0100"
}
但我想不出使用 select
、max_by
或 min_by
来实现此目的的方法。
我在 jq 1.4
将每个条目映射到 closedDate
过滤掉非值,然后获取最小值。
map(.closedDate | values) | min
我有一组对象如下,我正试图从所有对象中获取一个日期值。
期望的输出是:
"2014-12-16T08:59:08.000+0100"
数据集为:
[
{
"key": "AB-12345",
"type": "Fault",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad fault",
"closedDate": null,
"flag": null
},
{
"key": "AB-12346",
"type": "Bug",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad bug",
"closedDate": "2014-12-16T08:59:08.000+0100",
"flag": null
},
{
"key": "AB-12347",
"type": "Feature",
"typeid": "19",
"status": "Open",
"summary": "I'm a big bad feature",
"closedDate": "2014-12-17T08:27:07.000+0100",
"flag": null
}
]
我已经成功地使用了:
.[] | {"closedDate": .closedDate} | select(.closedDate > 0)
哪个会得到我:
{
"closedDate": "2014-12-16T08:59:08.000+0100"
}
{
"closedDate": "2014-12-17T08:27:07.000+0100"
}
但我想不出使用 select
、max_by
或 min_by
来实现此目的的方法。
我在 jq 1.4
将每个条目映射到 closedDate
过滤掉非值,然后获取最小值。
map(.closedDate | values) | min