Skip to content

Instantly share code, notes, and snippets.

@pritibiyani pritibiyani/json_to_csv.rb Secret
Created Jan 13, 2015

Embed
What would you like to do?
Usage: ./json_to_csv.rb {jsonFile}
#! /usr/bin/env ruby
# encoding: UTF-8
require 'csv'
require 'json'
f = File.open("./#{ARGV[0]}", "r")
csv_string = CSV.generate do |csv|
f.each_line do |json|
begin
hash = JSON.parse(json)
csv << hash.values
rescue Exception => e
puts e
end
end
end
File.open("#{ARGV[0]}.csv", "w") { |f| f.write(csv_string) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.