Create field with condition while looping through an array in ruby

And what if I want to get the result in a nested with something like that in the output :

"user": {
      "other" : {
            "address": "2 rue bidule",
            "city": "France",
            "contactNumber": "0600000000",
            "email": "test@test.com"
      }
}

How can I do it ?
If I try to add it in code like following I don't get my result

items_contact = event.get("[contact]")
    if items_contact != nil
        items_contact.each_with_index { |i, x|
            if (i["mediumType"] == "address") then
                if i["characteristic"]["street"] then
                    event.set("[user][other][address]", i["characteristic"]["street"])
                end
                if i["characteristic"]["city"] then
                    event.set("[user][other][city]", i["characteristic"]["city"])
                end
            elsif (i["mediumType"] == "contact") then
                if i["characteristic"]["contactNumber"] then
                    event.set("[user][other][contactNumber]", i["characteristic"]["contactNumber"])
                end
            elsif (i["mediumType"] == "email") then
                if i["characteristic"]["email"] then
                    event.set("[user][other][email]", i["characteristic"]["email"])
                end
            end
        }
    end