Sometimes, I have JSON arrays that I want to see as CSV
Here's my json_to_csv.rb
script. Not very sophisticated, but it does the job.
#!/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
Written by Aaron Spiegel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#