Skip to content

Instantly share code, notes, and snippets.

@epcim
Forked from X0nic/convert-csv-to-json.rb
Created May 28, 2018 08:15
Show Gist options
  • Save epcim/f71a286c562f65413cc846fa18686d39 to your computer and use it in GitHub Desktop.
Save epcim/f71a286c562f65413cc846fa18686d39 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