Skip to content

Instantly share code, notes, and snippets.

@X0nic
Created August 29, 2016 16:52
Show Gist options
  • Save X0nic/4971619cacd5b9503232736ccce4c237 to your computer and use it in GitHub Desktop.
Save X0nic/4971619cacd5b9503232736ccce4c237 to your computer and use it in GitHub Desktop.
Convert a csv to json
#! /usr/bin/env ruby
require 'csv'
require 'json'
csv = CSV.parse(File.read(file_name).scrub, headers: true)
hash = csv.map{ |row| { code: row["Classification Code"], description: row["Classification Code Description English"] } }
json = hash.to_json
File.write(new_file_name, json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment