Convert BSON.ObjectId to string in a list

Lets say i have a user information

User_map:

%{
  "groups_id" => [
    #BSON.ObjectId<59534f8a421aa917bc129841>, 
    #BSON.ObjectId<595351ab421aa917bc040b03>, 
    #BSON.ObjectId<5953519b421aa917bc716e1a>],
  "name" => "xxxl",
  "phone" => "12345",
  "user_id" => #BSON.ObjectId<59535602421aa917bc741e53>
}

Where groups_id contains list of ids of groups. Now i want to return this information in a JSON response, before that the groups_id having BSON.ObjectId in the list should be converted to string. How can i achive this? Alone for user_id i can convert but I am not getting to work for groups_id in list.

The easiest might be using update_in:

update_in(data, ["groups_id", Access.all()], &BSON.ObjectId.encode!/1)
4 Likes