Last active
April 16, 2019 14:17
-
-
Save hangingman/a0c7e966e3fd7cf5184881aab2345c98 to your computer and use it in GitHub Desktop.
JSONを再帰的にたどってkey, valueをCSV化する試み
This file contains hidden or 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" | |
def rec(json, prefix) | |
if json.class == Hash | |
json.each do |key, value| | |
rec(value, "#{prefix},#{key}") | |
end | |
elsif json.class == Array | |
json.each do |item| | |
rec(item, prefix) | |
end | |
else | |
puts "#{prefix},#{json}" | |
end | |
end | |
File.open("sample.json") do |j| | |
hash = JSON.load(j) | |
rec(hash, "") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment