Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key = "id", value = 1
- key = "mem/stat1", value = 10
- key = "more_stats/extra_stats/stat7", value = 5
- my_json =
- {
- "id": 1,
- "system_name": "System_1",
- "mem" : {
- "stat1" : 10,
- "stat2" : 1056,
- "stat3" : 10563,
- },
- "other_stats" : {
- "stat4" : 1,
- "stat5" : 2,
- "stat6" : 3,
- },
- "more_stats" : {
- "name" : "jdlfjsdlfjs",
- "os" : "fjsalfjsl",
- "error_count": 3
- "extra_stats" : {
- "stat7" : 5,
- "stat8" : 6,
- },
- }
- }
- def hashkeys(json, keys = [], result = [])
- if json.is_a?(Hash)
- json.each do |key, value|
- hashkeys(value, keys + [key], result)
- end
- else
- result << keys
- end
- result.join("/")
- end
- id/system_name/mem/stat1/mem/stat2/...
- nested_key_value(my_json)
- some logic loop involving key and value:
- send_info(final_key, final_value)
Add Comment
Please, Sign In to add comment