edthamm

CSV to JSON

Dec 4th, 2018
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.23 KB | None | 0 0
  1. require 'csv'
  2. require 'json'
  3.  
  4. input = CSV.new(File.open(ARGV[0]), headers: true, header_converters: :symbol, converters: :all)
  5. output = input.to_a.map { |row| row.to_hash }
  6. File.open(ARGV[1],"w") { |f| f.write(output.to_json) }
Advertisement