Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fully featured CSV parser for Haskell?

Tags:

csv

haskell

Can anybody recommend a way to parse CSV files with options to:

  • set cells/fields separator
  • set end of record/row terminator
  • set quote-character for fields
  • support of UTF-8 strings
  • ability to write in-memory CSV structure back to a file

I did try Text.CSV but it's very simple and lacks most of the above features. Is there some more advanced CSV parsing module or do I have to write it "from scratch" i.e. using Text.ParserCombinators? I do not intend to reinvent a wheel.

Take care.

like image 423
David Unric Avatar asked Jan 23 '11 12:01

David Unric


3 Answers

I can't recommend a ready-to-go, packaged-up CSV parser for Haskell, but I remember that the book Real-World Haskell by Bryan O'Sullivan et al. contains a chapter on Parsec, which the authors demonstrate by creating a CSV parser.

The relevant chapter 16: Using Parsec is available online; check the section titled Extended Example: Full CSV Parser.

like image 153
stakx - no longer contributing Avatar answered Nov 13 '22 06:11

stakx - no longer contributing


This is an old thread, but both csv-conduit and cassava have most, if not all -- not sure about re-writing to the file -- of the features you're looking for.

like image 25
amindfv Avatar answered Nov 13 '22 08:11

amindfv


A quick search on Hackage finds Data.Spreadsheet, which does have customizable quote and separator.

like image 4
ephemient Avatar answered Nov 13 '22 07:11

ephemient