I have a file.csv:
value1,value2
that I convert to JSON using the following command:
# adding headers on the fly
echo 'key1,key2' |
ruby -rcsv -rjson -e 'puts CSV.new(ARGF,headers:true).map(&:to_hash).to_json' - file.csv
The output should be:
[{"key1":"value1","key2":"value2"}]
Which is the case with ruby-2.0 and 2.3, but with ruby-2.7, the output is:
[]
Further debugging showed that ruby-2.7 CSV lib doesn't handle ARGF well, it stops the reading after the first file in ARGF (stdin in my case).
Are newer Ruby versions also affected by this issue? Is there a more portable way to do the same magic?