0

I have a hash table that looks like this:

hash =
"{\"url\":\"/system/message\",\"device\":\"UNKNOWN\",\"version\":\"1.0\",\"timestamp\":\"2018-08-28T11:16:29.516617Z\",\"object\":{\"timestamp\":\"2018-08-28T11:16:29.516490Z\",\"id\":9800,\"debug_level\":2,\"message\":\"Got new port configuration\"}}"

 hash.each do |variable|
    puts variable
 end

This do not work

Nico.E
  • 82
  • 11
user2909180
  • 203
  • 3
  • 11

2 Answers2

4

You'll need to first convert your string to a hash.

require 'json'

my_hash = JSON.parse(hash)
my_hash.each do |key, value|
  puts value
end
dkulkarni
  • 2,780
  • 4
  • 27
  • 36
0

You can also do the following:

require 'json'
values = JSON.parse(hash).map {|k,v| puts v }