Skip to content

Instantly share code, notes, and snippets.

@csaunders
Created December 10, 2012 23:49
Show Gist options
  • Save csaunders/4254449 to your computer and use it in GitHub Desktop.
Save csaunders/4254449 to your computer and use it in GitHub Desktop.
Turn CSV into JSON like a boss
require 'rubygems'
require 'csv'
require 'json'
file = CSV.new(File.new('stuff_i_need_to_extract.csv', 'rb'), :headers => true).read
result = []
result = file.map do |row|
extract_data_from_row(row)
end
File.open('output.json', 'wb') do |f|
f << result.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment