Created
July 31, 2017 11:24
-
-
Save darelvc/f34b65a9695d23bcda10dfe2106f856a to your computer and use it in GitHub Desktop.
null created by darelvc - https://repl.it/JqDH/12
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
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