Last active
November 7, 2016 23:16
-
-
Save maxjacobson/444eb94980ab7dd1480ef3e92d825451 to your computer and use it in GitHub Desktop.
handy script to print out the structure of a json file
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
#!/usr/bin/env ruby | |
require 'json' | |
require 'yaml' | |
def simple_structure(orig) | |
case orig | |
when Hash | |
simple = {} | |
orig.each do |key, value| | |
simple[key] = simple_structure(value) | |
end | |
simple | |
when Array | |
orig.map { |v| simple_structure(v) }.uniq | |
else | |
orig.class.name | |
end | |
end | |
puts YAML.dump simple_structure JSON.parse File.read ARGV.fetch(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment