Convert BSON.ObjectId to string in a list

Lets say i have a user information


  "groups_id" => [
  "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)