script

script

Nested list value inside map csv export

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

First Post!

NobbZ

NobbZ

Which library are you using for CSV export?

Last Post!

script

script

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

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement