Skip to content

Instantly share code, notes, and snippets.

@dgrstl
Created November 3, 2015 03:41
Show Gist options
  • Save dgrstl/f453e1b8417cddeda7ad to your computer and use it in GitHub Desktop.
Save dgrstl/f453e1b8417cddeda7ad to your computer and use it in GitHub Desktop.
require 'json'
require 'csv'
f = File.open('foo.json')
csv_out = CSV.generate do |csv|
nodes = JSON.parse(f.read)
#create header
entry = nodes.first
csv << ['node'] + entry[1].keys
#output one record per node
nodes.each do |node_name, facts|
csv << [node_name] + facts.values
end
end
puts csv_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment