How to transform a stream of arrays to CSV in JQ?

Viewed 44

I've got this informations from a json file aplying jq filter, now I need to transform this in a csv file but I don't know how to do.

The file:

[
  "https://localhost/rundeck/project/Enterprise/execution/show/228",
  "succeeded",
  "Enterprise",
  "2020-04-19T03:00:01Z",
  "2020-04-19T03:13:17Z",
  "job_particion"
]
[
  "https://localhost/rundeck/project/Enterprise/execution/show/824",
  "succeeded",
  "Enterprise",
  "2020-09-01T04:15:00Z",
  "2020-09-01T04:15:02Z",
  "job_scheduler"
]
[
  "https://localhost/rundeck/project/Enterprise/execution/show/822",
  "succeeded",
  "Enterprise",
  "2020-09-01T03:45:00Z",
  "2020-09-01T03:45:06Z",
  "job_system"
]
[
  "https://localhost/rundeck/project/Enterprise/execution/show/823",
  "succeeded",
  "Enterprise",
  "2020-09-01T04:00:00Z",
  "2020-09-01T04:00:25Z",
  "job_operator"
]
[
  "https://localhost/rundeck/project/Enterprise/execution/show/821",
  "succeeded",
  "Enterprise",
  "2020-09-01T03:30:00Z",
  "2020-09-01T03:30:10Z",
  "job_aplication"
]

I see this ERROR when I try like this:

cat file.json | jq '.[]| join(",")'
jq: error (at <stdin>:8): Cannot iterate over string ("https://lo...)
1 Answers

It's easier than you think:

jq -r '@csv' file.json

Online demo

Related