Skip to content

Instantly share code, notes, and snippets.

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 ="/path/to/file/#{file_name}.csv", 'rb').read
csv =, :headers => true, :header_converters => :symbol, :converters => :all)
weather = {|row| row.to_hash }"/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.