0

How can i get the attributes of this payload?, one, two, three are not static attributes, they could be whatever, now i want to get the "one": "1", "two": "2",...

{
 "section": "factor",
 "data": {
    "one": "1",
    "two": "2",
    "three": "3"
  }
}

my attempt is params[:data][1], but how to know if there is the element [1]...

i need to iterate, how to get the key and value

tunosi st
  • 23
  • 3
  • https://stackoverflow.com/questions/1227571/how-to-get-a-specific-output-iterating-a-hash-in-ruby – dbugger Mar 29 '23 at 11:03

1 Answers1

1

The following would be working:

payload = {
  "section": "factor",
  "data": {
    "one": "1",
    "two": "2",
    "three": "3"
  }
}

data = payload[:data]

data.each_pair do |key,value|
  puts "#{key}:#{value}"
end
titan2gman
  • 408
  • 9