1

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?

1 Answer 1

3

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"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.