Skip to content

Instantly share code, notes, and snippets.

@maxjacobson
Last active November 7, 2016 23:16
Show Gist options
  • Save maxjacobson/444eb94980ab7dd1480ef3e92d825451 to your computer and use it in GitHub Desktop.
Save maxjacobson/444eb94980ab7dd1480ef3e92d825451 to your computer and use it in GitHub Desktop.
handy script to print out the structure of a json file
#!/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