Last active
July 16, 2019 11:20
-
-
Save yevgenko/f9b473fa2c32c5b207847178b15f8a01 to your computer and use it in GitHub Desktop.
Convert flatfile.io output (key-value map) to CSV string.
This file contains 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' | |
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