Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created August 6, 2015 10:30
Show Gist options
  • Select an option

  • Save h2rd/191509d716fb5643e3ae to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/191509d716fb5643e3ae to your computer and use it in GitHub Desktop.
require 'json'
require 'csv'
raise Exception, 'you must provide a json file' unless ARGV[0]
buffer = File.open(ARGV[0]).read
buffer.gsub!("\n", '')
buffer.gsub!("\t", '')
json = JSON.parse!(buffer)
puts json.first.collect {|k,v| k}.to_csv
puts json.collect {|node| node.collect{|k,v| "#{v}"}.to_csv}.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment