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.
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:
Expected:
{
"username":"achu",
"password":"test1234",
"date":"1:20:30 AM PST"
}
jq --version
1.5v
Is it possible to get it like this?
JQ has builtin functions for playing with dates, such as:
. + {date: (now | strflocaltime("%r"))}
One of many possibilities:
$ jq --arg date $(date +"%r") '. + {date: $date}'
p.s. The jq program could be written as:
. + {$date}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With