Skip to content

Instantly share code, notes, and snippets.

@kechol
Last active January 21, 2019 15:10
Show Gist options
  • Save kechol/0c7972a0cb93da49ac79f1cae50eda48 to your computer and use it in GitHub Desktop.
Save kechol/0c7972a0cb93da49ac79f1cae50eda48 to your computer and use it in GitHub Desktop.
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