Reputation: 1246
Using jq
to convert a json array to csv results in this:
$ echo '["a",1,true,"comment"]' | jq '.|@csv'
"\"a\",1,true,\"comment\""
I am surprised that the entire array becomes one string rather than a list of values. What can I do to get
"a",1,true,"comment"
instead?
Upvotes: 1
Views: 1126
Reputation: 134801
You misunderstand the point of the @
filters. These are string formatting filters, they yield strings. So @csv
returns a string representation of the array as a csv row. That's precisely what it's supposed to. It would be wrong for it to return the "unstringified" version because it would not be possible to process any further.
If you want the raw "unstringified" output, use the -r
raw output option.
$ echo '["a",1,true,"comment"]' | jq -r '@csv'
"a",1,true,"comment"
Upvotes: 3