Skip to content

Instantly share code, notes, and snippets.

@cwoodcox
Created March 26, 2012 18:11
Show Gist options
  • Save cwoodcox/2208201 to your computer and use it in GitHub Desktop.
Save cwoodcox/2208201 to your computer and use it in GitHub Desktop.
require 'json'
require 'csv'
require 'pry'
data = JSON.parse(DATA.read)
CSV.open 'data.csv', 'wb' do |csv|
mapping = {
"name" => "custom_field_1",
"email" => "custom_field_4",
"phone" => "custom_field_3",
"location" => "custom_field_2",
"type" => "custom_field_6",
"stage_1_location" => "custom_field_19",
"stage_1_role" => "custom_field_20",
"stage_3_location" => "custom_field_21",
"stage_3_role" => "custom_field_22",
"stage_4_location" => "custom_field_23",
"stage_4_role" => "custom_field_24",
"stage_5_location" => "custom_field_25",
"stage_5_role" => "custom_field_26",
"stage_6_location" => "custom_field_27",
"stage_6_role" => "custom_field_28",
"comments" => "comments"
}
csv << mapping.keys
data.each do |obj|
csv << mapping.values.collect do |val|
obj[val]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment