-
-
Save pritibiyani/631bfec84b892d76aca6 to your computer and use it in GitHub Desktop.
Usage: ./json_to_csv.rb {jsonFile}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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