Haskell – Fully featured CSV parser for Haskell

csvhaskell

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.

Best Answer

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.