I am trying to loop through some video objects and i am trying to build a JSON array that looks like this:
[{"event_name":"video_completed","object_id":123456789}]
I created a method to do this:
def self.getEngagementRules(videos)
rules = []
videos.each do |video|
rule = {
event_name: "video_completed",
object_id: video.image_hash.to_i
}
rules << rule.to_json
end
rules
end
I am creating hashes and then turning them into JSON and appending it to my array rules but when i run:
puts rules
i get {"event_name":"video_completed","object_id":123456789}
instead of [{"event_name":"video_completed","object_id":123456789}]
What is the correct way of doing this so i can loop through multiple videos and get my desired result.
It should be able to handle multiple videos and output:
[{"event_name":"video_completed","object_id":123456789}, {"event_name":"video_completed","object_id":123456789}]
ruleinstead ofrulesby mistake? Also, each element in your array will be a string representing a JSON["{\"event_name\":\"video_completed\",\"object_id\":1234}"]