# Working with Nested structures

**URL:** <https://forum.elixirforum.com/t/working-with-nested-structures/38303>\
**Category:** Questions\
**Tags:** list-of-nested-map-help\
**Created:** [March 19, 2021, 7:17am UTC](https://forum.elixirforum.com/t/working-with-nested-structures/38303 "2021-03-19T07:17:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kokolegorille](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kokolegorille/32/4784_2.png) [@kokolegorille](https://forum.elixirforum.com/u/kokolegorille)\
**Post date:** [March 19, 2021, 7:37am UTC](https://forum.elixirforum.com/t/working-with-nested-structures/38303/2 "2021-03-19T07:37:53Z")

</div>

Hello and welcome,

There are many ways to update/put a key in a map, Map.update, Map.put, Map.new/2, but in that particular case where You want to update an existing atom key in a map, You can use the form map = %{map | key: value}

You can do like this…

```elixir
iex(1)> map = %{
  tasks: [
    %{completed: false, date_added: "3.18.2021", id: 1, name: "walk the dog"},
    %{completed: false, date_added: "3.18.2021", id: 2, name: "cook dinner"},
    %{completed: false, date_added: "3.18.2021", id: 3, name: "laundry"}
  ]
}
iex(2)> i = 1
iex(3)> map = %{map | tasks: Enum.map(map.tasks, fn 
  task when task.id==id -> %{task | completed: true}
  task -> task 
end)}
%{
  tasks: [
    %{completed: true, date_added: "3.18.2021", id: 1, name: "walk the dog"},
    %{completed: false, date_added: "3.18.2021", id: 2, name: "cook dinner"},
    %{completed: false, date_added: "3.18.2021", id: 3, name: "laundry"}
  ]
}

```

---

_[View the full topic](https://forum.elixirforum.com/t/working-with-nested-structures/38303)._
