`jq` can transform CSV to JSON and vice-versa, especially for simple/naive data where simply splitting on `,` is good enough - and where you aren't too bothered by types (e.g. if you don't mind numbers ending up as strings).<p>First attempt is to simply read each line in as raw and split on `,` - sort of does the job of, but it isn't the array of arrays that you might expect:<p><pre><code> $ echo -e "foo,bar,quux\n1,2,3\n4,5,6\n7,8,9" > foo.csv
$ jq -cR 'split(",")' foo.csv
["foo","bar","quux"]
["1","2","3"]
["4","5","6"]
["7","8","9"]
</code></pre>
Pipe that back to `jq` in slurp mode, though:<p><pre><code> $ jq -R 'split(",")' foo.csv | jq -cs
[["foo","bar","quux"],["1","2","3"],["4","5","6"],["7","8","9"]]
</code></pre>
And if you prefer objects, this output can be combined with the csv2json recipe from the jq cookbook[0], without requiring `any-json` or any other external tool:<p><pre><code> $ jq -cR 'split(",")' foo.csv | jq -csf csv2json.jq
[{"foo":1,"bar":2,"quux":3},
{"foo":4,"bar":5,"quux":6},
{"foo":7,"bar":8,"quux":9}]
</code></pre>
Note that this recipe also keeps numbers as numbers!<p>In the reverse direction there's a builtin `@csv` format string. This can be use with the second example above to say "turn each array into a CSV row" like so:<p><pre><code> $ jq -R 'split(",")' foo.csv | jq -sr '.[]|@csv'
"foo","bar","quux"
"1","2","3"
"4","5","6"
"7","8","9"
</code></pre>
And to turn the fuller structure from the third example back into CSV, you can pick out the fields, albeit this one is less friendly with quotes and doesn't spit out a header (probably doable by calling `keys` on `.[0]` only...):<p><pre><code> $ jq -cR 'split(",")' foo.csv | jq -csf csv2json.jq | \
> jq -r '.[]|[.foo,.bar,.quux]|@csv'
1,2,3
4,5,6
7,8,9
</code></pre>
I don't consider myself much of a jq power user, but I am a huge admirer of its capabilities.<p>[0] <a href="https://github.com/stedolan/jq/wiki/Cookbook#convert-a-csv-file-with-headers-to-json" rel="nofollow">https://github.com/stedolan/jq/wiki/Cookbook#convert-a-csv-f...</a>