如何使用jq将当前日期和时间附加到现有的json文件中 [英] How to append current date and time into existing json file using jq

查看:87
本文介绍了如何使用jq将当前日期和时间附加到现有的json文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的json文件格式如下

I have below format of json file

{
  "username":"achu",
  "password":"test1234"
}

我只想将时间戳添加到上述有效负载中,并作为对某些服务的请求发送.

I just want to add timestamp into the above payload and send it as request for some service.

据我所知,以下命令将帮助我们在Linux上获取当前戳记:

AS per I know the below command will help us to get current stamp on linux:

date +"%r"

但不确定如何将其附加到上述有效负载中,如下所示:

but not sure how can I append this into the above payload as like below:

预期:

{
  "username":"achu",
  "password":"test1234",
  "date":"1:20:30 AM PST"
}

jq --version

jq --version

1.5v

有可能这样得到吗?

推荐答案

众多可能性之一:

$ jq --arg date $(date +"%r") '. + {date: $date}'

p.s. jq程序可以写为:

p.s. The jq program could be written as:

. + {$date}

p.p.s.与其不断询问使用jq是否有可能,您可能会发现花费更多的时间来更加熟悉jq.官方手册是一个很好的参考: https://stedolan.github.io/jq/manual/

p.p.s. Rather than continually asking whether something is possible using jq, you might find it a better investment of your time to become more familiar with jq. A good reference is the official manual: https://stedolan.github.io/jq/manual/

这篇关于如何使用jq将当前日期和时间附加到现有的json文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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