Last active
January 21, 2019 15:10
-
-
Save kechol/0c7972a0cb93da49ac79f1cae50eda48 to your computer and use it in GitHub Desktop.
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
require "json" | |
require "csv" | |
@rows = [] | |
def row(val, key) | |
val.each do |k, next_val| | |
next_key = [key, k].join(".") | |
if Hash === next_val | |
row(next_val, next_key) | |
else | |
@rows << [next_key, next_val] | |
end | |
end | |
end | |
row(JSON.parse(STDIN.read), "") | |
csv = CSV.generate(col_sep: "\t") {|csv| @rows.each {|r| csv << r } } | |
File.write("ja.csv", ("\uFEFF" + csv).encode(Encoding::UTF_16LE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment