Skip to content

Instantly share code, notes, and snippets.

@mjacobus
Created September 23, 2020 13:56
Show Gist options
  • Save mjacobus/ffbe3b190b384f9bf75f6bcd1073dd11 to your computer and use it in GitHub Desktop.
Save mjacobus/ffbe3b190b384f9bf75f6bcd1073dd11 to your computer and use it in GitHub Desktop.
require 'csv'
require 'json'
hash = { x: 'y', 'z': 611 }
CSV.open('tmp/csv_with_json.csv', 'wb') do |csv|
csv << ['a', hash.to_json, 'b']
csv << ['a', hash.to_json, 'b']
end
@mjacobus
Copy link
Author

This is the resulting csv:

a,"{""x"":""y"",""z"":611}",b
a,"{""x"":""y"",""z"":611}",b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment