# Nested list value inside map csv export

**URL:** <https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532>\
**Category:** Questions\
**Tags:** csv\
**Created:** [January 19, 2019, 11:40am UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532 "2019-01-19T11:40:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![script](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/script/32/8725_2.png) [@script](https://forum.elixirforum.com/u/script)\
**Post date:** [January 19, 2019, 11:40am UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532/1 "2019-01-19T11:40:14Z")

</div>

The code is working fine it takes list of maps convert them into csv and export the value. This is the code

```
def to_csv(map, path) do
  file = File.open!(path, [:write, :utf8])
  map
   |> IO.inspect()
   |> CSV.encode(headers: true)
   |> Enum.each(&IO.write(file, &1))
end

```

This is the list of maps

```
%{
name: "Kelsie",    
date_of_birth: ~D[1944-06-02],
end_date: ~D[2017-10-30],   
category_id: [14, 9, 19, 14], 
room_name: "Filomena",
id: 11, 
},
%{ 
name: "Karson",
date_of_birth: ~D[1944-06-02],  
end_date: ~D[2017-11-04], 
category_id: [15, 19, 7, 14, 9],
room_name: "Bert",
id: 12,    
}
]

```

File is exporting successfully but the list of category ids not inserting . I just got `\t\n` in the place of category id.  
Any suggestions?  
If its possible?  
Thanks

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [January 19, 2019, 11:48am UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532/2 "2019-01-19T11:48:30Z")

</div>

Which library are you using for CSV export?

---

<div class="post-metadata">

**Author:** ![script](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/script/32/8725_2.png) [@script](https://forum.elixirforum.com/u/script)\
**Post date:** [January 19, 2019, 11:50am UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532/3 "2019-01-19T11:50:05Z")

</div>

[https://github.com/beatrichartz/csv](https://github.com/beatrichartz/csv)

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [January 19, 2019, 11:58am UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532/4 "2019-01-19T11:58:34Z")

</div>

That uses `to_string/1` to encode anything but a `BitString`. So you probably hit a charlist issue here.

You need to preprocess your data properly to make it encodable.

---

<div class="post-metadata">

**Author:** ![script](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/script/32/8725_2.png) [@script](https://forum.elixirforum.com/u/script)\
**Post date:** [January 19, 2019, 12:10pm UTC](https://forum.elixirforum.com/t/nested-list-value-inside-map-csv-export/19532/5 "2019-01-19T12:10:00Z")

</div>

Thanks for your answer. I just went with using map instead of list for category\_id and encode it with poison. It seems to work
