Home > database >  convert a json to a csv, array
convert a json to a csv, array

Time:12-15

I'd like to convert below file into a csv file, I think jq would be the suitable tool for it.

[
  [
    "123456789012",
    "071395e8xxxxxxxx",
    bad,
    failed
  ],
  [
    "098765432123",
    "094e9c34d3xxxxxxxx",
    good,
    successful
  ],
  ...
]

to

123456789012,071395e8xxxxxxxx, bad, failed
098765432123,094e9c34d3xxxxxxxx,good,successful

CodePudding user response:

Unfortunately, the input as shown is not quite valid JSON, so you would have to tweak it somehow before presenting it to JSON. The jq command for converting to CSV would then be along the lines of:

jq -r '.[] | @csv' input.json
  • Related