Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convert a csv file to json
require 'csv'
require 'json'
date = 5
file_name = "weather-2014-12-#{date}"
body = File.open("/path/to/file/#{file_name}.csv", 'rb').read
csv = CSV.new(body, :headers => true, :header_converters => :symbol, :converters => :all)
weather = csv.to_a.map {|row| row.to_hash }
File.open("/path/to/file/#{file_name}.json", 'w') { |f| f.write(weather.to_json) }
# replace null with "" manually
# run putil command
# plutil -convert xml1 weather-2014-12-[DATE].json -o weather-2014-12-[DATE].plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.