Skip to content

Instantly share code, notes, and snippets.

@spiegela
Created August 4, 2013 20:45
Show Gist options
  • Select an option

  • Save spiegela/6151875 to your computer and use it in GitHub Desktop.

Select an option

Save spiegela/6151875 to your computer and use it in GitHub Desktop.
Sometimes, I get JSON arrays, and I want them to be CSV files.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
raise Exception, 'you must provide a json file' unless ARGV[0]
json = JSON.parse(File.open(ARGV[0]).read)
puts json.first.collect {|k,v| k}.join(',')
puts json.collect {|node| "#{node.collect{|k,v| v}.join(',')}\n"}.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment