jQuery按日期过滤JSON [英] jq filter json by dates

查看:105
本文介绍了jQuery按日期过滤JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些像这样的json

I have some json that looks like this

 {
  "users":[ {  
     "id":8734,
     "last_login":"2016-10-04T06:59:40Z"
  },
  {  
    "id":9376,
    "last_login":"2016-05-04T20:37:32Z"
  },
  {  
    "id":9376,
    "last_login":null
  }
]}

我想返回上次登录日期为> 90天的id,因此在这种情况下,它应该只返回9376.我想我需要将fromdateiso8601与select结合使用,但是在正确使用语法方面有些麻烦.

I want to return ids that the last login date is > 90days so in this case it should only return 9376. I am thinking I need to use fromdateiso8601 in combination with a select but am having a little trouble getting the syntax right.

这似乎可行

.users[] | select ( .last_login | fromdateiso8601 > 1475625600) | .id 

但是我仍然得到

jq: error (at <stdin>:0): strptime/1 requires string inputs and arguments

我该如何处理null,理想情况下应将其包含在结果中.

how do I deal with the null, ideally those would be included in the results.

推荐答案

只需添加适当的null检查.

Just add the appropriate null checks.

.users[] | select (.last_login | . == null or fromdateiso8601 > 1475625600).id 

这篇关于jQuery按日期过滤JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆