1

I’m having trouble removing double quotes from the date I pass in to JQ. Any idea how I can do that? -r doesn’t seem to do the trick.

curl SOMETHING | jq -r --arg date $(date +"%s") '.payload.overallStatus | [$date, .totalTimeSpent, .totalRecords, .totalDuplicates]'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   607  100   607    0     0  10649      0 --:--:-- --:--:-- --:--:-- 10649
[
  "1594330317",
  15802,
  89004346,
  10
]

(I plan to add the | @csv option to convert the output to a line of csv)

gatech-kid
  • 67
  • 8
  • 1
    `tonumber`, as per https://stackoverflow.com/q/48887711/3266847? – Benjamin W. Jul 09 '20 at 21:39
  • jq -r --arg date $(date +"%s") '.payload.overallStatus | [$date|tonumber, .totalTimeSpent, .totalRecords, .totalDuplicates]’ creates error jq: error (at :22): Cannot index string with string "totalTimeSpent" – gatech-kid Jul 09 '20 at 21:42

1 Answers1

1

Use tonumber. You need to use parentheses not to change the context for the remaining elements of the array.

[($date | tonumber), .totalTimeSpent, .totalRecords, .totalDuplicates]

Without the parentheses, the expression is equivalent to

[$date | (tonumber, .totalTimeSpent, .totalRecords, .totalDuplicates)]
choroba
  • 231,213
  • 25
  • 204
  • 289