Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created March 10, 2010 21:10
Show Gist options
  • Save msonnabaum/328404 to your computer and use it in GitHub Desktop.
Save msonnabaum/328404 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'fastercsv'
require 'json'
class Cvs2json
attr_reader :csv
def initialize(filename)
@filename = filename
@csv = FasterCSV.read(@filename, {:converters => :all} )
end
def tojson
json_file = File.basename(@filename, '.csv')
File.open("#{json_file}.js", 'w') do |f|
f.puts(@csv.to_json)
end
end
end
b = Cvs2json.new(ARGV[0])
b.tojson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment