I am trying to use jq
to reformat some elements of the JSON output generated by ffprobe
as csv
. I'm close (it seems to me), but struggling with a detail:
My ffprobe
output is shown in the jq 1.6 playground
I'm running a recently d/l binary of jq (jq --version
=> jq-1.6
) on MacOS Mojave (10.14.6)
From the terminal on my Mac, my results are:
$ fn_ffprobeall | jq -r '[.format.filename,.format.format_name,.format.tags.album_artist] | @csv'
"01 Jubilee.flac","flac","Bill Charlap Trio"
# where fn_ffprobeall is a function defined as:
fn_ffprobeall () { ffprobe -i "01 Jubilee.flac" -hide_banner -v quiet -print_format json -show_format -show_streams; }
But this jq
output (shown above) is not what I need... I need values without the surrounding quotes ""
. According to the documentation for --raw-output / -r
:
With this option, if the filter’s result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for making jq filters talk to non-JSON-based systems.
Also, it seems odd that using @tsv
instead of @csv
"does the right thing" as the quotes will be stripped. I suppose one could do some additional work to replace tab
chars with ,
, but I'd like to know if I'm missing something before falling back to that approach.
jq
documentation was as clear :) And fwiw, I was trying to add the string as a row in an existing CSV file using Excel. – Favata