Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert flatfile.io output (key-value map) to CSV string.
require 'csv'
require 'json'
def flatfile_io_json2csv_string(data_as_string = '[{"sku_code": "123"}, {"sku_code": "321"}]')
CSV.generate do |csv|
json_data = JSON.parse(data_as_string)
csv << json_data.first.keys # header
json_data.each do |hash|
csv << hash.values
end
end
end
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.