Created
December 19, 2014 17:25
-
-
Save armstrongnate/6db0b2d81d6803063235 to your computer and use it in GitHub Desktop.
convert a csv file to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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