Skip to content

Instantly share code, notes, and snippets.

@etagwerker
Created May 7, 2013 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etagwerker/5532467 to your computer and use it in GitHub Desktop.
Save etagwerker/5532467 to your computer and use it in GitHub Desktop.
read a csv file and convert it to a json string
require 'csv'
require 'json'
csv =CSV.parse(File.read('lib/data/GeoPC_Regions_ISO3166_2.csv'),{:col_sep => ";"})
JS = []
csv.each do |row|
h = {iso: row[0],
country: row[1],
iso2: row[2],
region: row[3],
alt_name_1: row[4],
alt_name_4: row[5]}
JS << h
end
JS.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment