# Convert a nested struct into a nested map

**URL:** <https://forum.elixirforum.com/t/convert-a-nested-struct-into-a-nested-map/23814>\
**Category:** Questions\
**Tags:** elixir-map\
**Created:** [July 8, 2019, 6:46pm UTC](https://forum.elixirforum.com/t/convert-a-nested-struct-into-a-nested-map/23814 "2019-07-08T18:46:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![wolfiton](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wolfiton/32/15884_2.png) [@wolfiton](https://forum.elixirforum.com/u/wolfiton)\
**Post date:** [July 8, 2019, 6:52pm UTC](https://forum.elixirforum.com/t/convert-a-nested-struct-into-a-nested-map/23814/2 "2019-07-08T18:52:31Z")

</div>

Hello,

Welcome to the forum

This may help you  
from\_struct(struct)[View Source](https://github.com/elixir-lang/elixir/blob/v1.6.5/lib/elixir/lib/map.ex#L853)

from\_struct([atom](https://hexdocs.pm/elixir/1.6.5/typespecs.html#basic-types)() | [struct](https://hexdocs.pm/elixir/1.6.5/typespecs.html#basic-types)()) :: [map](https://hexdocs.pm/elixir/1.6.5/typespecs.html#basic-types)()

Converts a `struct` to map.

It accepts the struct module or a struct itself and simply removes the ` __struct__ ` field from the given struct or from a new struct generated from the given module.

## Example

```elixir
defmodule User do
  defstruct [:name]
end

Map.from_struct(User)
#=> %{name: nil}

Map.from_struct(%User{name: "john"})
#=> %{name: "john"}

```

---

_[View the full topic](https://forum.elixirforum.com/t/convert-a-nested-struct-into-a-nested-map/23814)._
