Skip to content

Instantly share code, notes, and snippets.

@darelvc
Created July 31, 2017 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darelvc/f34b65a9695d23bcda10dfe2106f856a to your computer and use it in GitHub Desktop.
Save darelvc/f34b65a9695d23bcda10dfe2106f856a to your computer and use it in GitHub Desktop.
null created by darelvc - https://repl.it/JqDH/12
require 'json'
a = { "system": {"cpu": {"softirq": {"pct": 0}, "idle": {"pct": 0.992}, "steal": {"pct": 0}, "cores": 1, "system": { "pct": 0.0003 }, "iowait": { "pct": 0.007 }, "irq": { "pct": 0 }, "user": { "pct": 0.0007 }, "nice": { "pct": 0 } }} }
parsed = a.to_json
json_parsed = JSON.parse(parsed)
global_key = json_parsed.keys()
json_parsed[global_key[0]].each do |key, value|
second_key = key
# puts second_key
value.each do |k, v|
if v.is_a?(Hash)
v.each do |z, x|
puts "#{global_key[0]}.#{second_key}.#{k}.#{z} #{x}"
end
else
puts "#{global_key[0]}.#{second_key}.#{k} #{v}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment