Archive for September, 2014

CSV to JSON Convert Ruby

Here. Easy way to convert your CSV (with headers) to a representative json hash. It just creates a file with .json tacked onto the end.

require 'json'
require 'csv'

file_name="observations.csv"

File.open("#{file_name}.json", "w") { |f| f.write(CSV.open(file_name, headers: true, header_converters: :symbol, converters: :all).to_a.map(&:to_hash).to_json) }
© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top