json - 使用 jq 获取具有最新时间戳的 json 对象
问题描述
我有一个下面的 json 文件,但我正在努力只显示description
最新的createdDate
.
我试过了
>
<
todateiso8601?
now
还有一些,但我无法让它工作。
有人能帮忙吗?
JSON:
{
"items": [
{
"createdDate": 1543585940,
"id": "awefef",
"description": "this is description 1"
},
{
"createdDate": 1555324487,
"id": "hjkvhuk",
"description": "this is description 2"
},
{
"createdDate": 1547034297,
"id": "xdfxdfv",
"description": "this is description 3"
}
]
}
解决方案
只需按 .createdDate 排序并(假设您只需要一个值,即使有多个具有最大 .createdDate 值的值),选择最后一个:
.items
| sort_by(.createdDate)[-1].description
领带
如果您想要关系的所有描述:
.items
| sort_by(.createdDate)
| (.[-1].createdDate) as $max
| .[]
| select($max == .createdDate)
| .description
推荐阅读
- sikuli - 我们可以从 sikuli 创建独立的 exe 文件吗?
- python - 绘制自制的分段函数出了问题
- scala - 多个目标的 Sbt 组装
- c++ - 检查注册表项是否链接到(或副本)另一个
- sql-server - SQL 2016 中用于返回 XML 的 URL
- android - 得到 NetworkInfo 状态:DISCONNECTED/BLOCKED 即使手机已连接
- ios - 提供的注册令牌未注册
- docker - AspNet Core 不在 docker ["ASPNETCORE_ENVIRONMENT=Production"] 上的生产环境中运行
- javascript - 选择器示例给出了一个 TypeError
- workflow - 我部署的 .bpmn2 文件无法识别在露天 rest-api 的 (/processes POST) 的 processBody 中设置的自定义变量