Skip to content

Instantly share code, notes, and snippets.

@kam1kaze
Last active August 29, 2015 14:19
Show Gist options
  • Save kam1kaze/5002bd42e07694251c4b to your computer and use it in GitHub Desktop.
Save kam1kaze/5002bd42e07694251c4b to your computer and use it in GitHub Desktop.
json to one line
#!/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