Hey, help me fix wha I am doing wrong in jq, I need to change two EPOCH TS to human readable, I am trying gjq '.secondary|{.last_try,.last_xfr}|= todate|.last_try,.last_xfr' but I am doing it wrong, and can't remember the correct syntax
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! To convert two epoch timestamps to human-readable format using jq, you need to correctly apply the todate function to each of the fields you want to convert. Here’s how you can do it:
However, todate is not a built-in jq function. You’ll need to define it or use a combination of existing functions to achieve the conversion. Here’s how you can define a todate function within jq:
sh
jq 'def todate: . as $in | if $in then ($in / 1000 | strftime("%Y-%m-%dT%H:%M:%SZ")) else $in end; .secondary | (.last_try, .last_xfr) |= todate' input.json
This command does the following:
Defines a todate function that converts the epoch timestamp to a human-readable format.
Applies this function to the last_try and last_xfr fields within the secondary object.
Note: The todate function assumes the timestamp is in seconds. If your timestamp is in milliseconds, you would need to adjust the division accordingly (i.e., / 1000).
User
Cheers! jq '.secondary | (.last_try, .last_xfr) |= (todate)' input.json did the trick. always forget some syntax :( thanks
Assistant
You're welcome! I'm glad to hear that the command worked for you. It's easy to forget syntax details, especially with tools like jq that have a lot of powerful features. If you have any more questions or need further help with jq or anything else, feel free to ask!