Created
November 20, 2014 20:22
-
-
Save eskfung/f0d6bac6e196bd77228c to your computer and use it in GitHub Desktop.
KM People JSON to CSV
This file contains hidden or 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' | |
data = { | |
# simplifying returned results | |
"total" => nil, | |
"links" => [], | |
"metadata" => {}, | |
"columns"=> [ | |
{ | |
"display_name"=>"KMID", | |
"type"=>"internal", | |
"return_option"=>"internal", | |
"display_return_option"=>"internal" | |
}, | |
{ | |
"display_name"=>"Person", | |
"type"=>"internal", | |
"return_option"=>"internal", | |
"display_return_option"=>"internal" | |
}, | |
{ | |
"type"=>"event", | |
"display_name"=>"Visited Site", | |
"return_option"=>"total_times_ever", | |
"display_return_option"=>"Total Times Ever" | |
} | |
], | |
"rows"=> [ | |
[12345, "[email protected]", 22] | |
] | |
} | |
CSV.generate do |writer| | |
writer << data.fetch('columns').map {|column| column.fetch('display_name', '')} | |
data.fetch('rows').each do |row| | |
writer << row | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment