Last active
August 29, 2015 14:19
-
-
Save kam1kaze/5002bd42e07694251c4b to your computer and use it in GitHub Desktop.
json to one line
This file contains 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 | |
# Usage: | |
# cat some.json | ruby -e "$(curl -s https://gist.githubusercontent.com/kam1kaze/5002bd42e07694251c4b/raw/json_to_line)" | |
require 'json' | |
r = JSON.parse(ARGF.read) | |
def extract(hash, parent) | |
hash.each_pair { |key, value| | |
if value.is_a?(Hash) | |
extract(value, parent + "::" + key) | |
else | |
print parent + "::" + key + ": " + value.to_s + "\n" | |
end | |
} | |
end | |
extract(r, "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment