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 =!(path, [:write, :utf8])
   |> IO.inspect()
   |> CSV.encode(headers: true)
   |> Enum.each(&IO.write(file, &1))

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?

Which library are you using for CSV export?

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.

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