Created
June 11, 2019 18:47
-
-
Save tlehman/af602be1fc4cc2fe43516c943c3b516e to your computer and use it in GitHub Desktop.
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 | |
# display tree of json key names | |
# like tree(1) for JSON | |
# by @tlehman | |
require 'json' | |
input = STDIN.read || File.open(ARGV.first).read | |
parsed_input = JSON.parse(input) | |
def puts_keys(hash, indent_level = 0) | |
# and all hash key children | |
indent = " " * indent_level | |
hash.keys.each do |key| | |
puts indent + key | |
if hash[key].is_a?(Hash) | |
puts_keys(hash[key], indent_level + 1) | |
end | |
end | |
end | |
puts_keys(parsed_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment