Kurren123 / elm-csv-decode

Decode CSV records to types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Csv.Decode

CSV decoding, heavily inspired by url-parser.

Note this library does not include an underlying CSV parser. It assumes you are using something like periodic/elm-csv or lovasoa/elm-csv to get from String to Csv, where Csv is:

type alias Csv =
  { headers : List String
  , records : List (List String)
  }

This library gets you the rest of the way, to a list of your own types. It also collects errors together with the index of the record they occurred on.

You can think of this as analogous to Json.Decode. It lets you declaratively convert data from an intermediate representation (Json.Value or Csv) into your own types.

Basic usage

Using periodic/elm-csv (which returns a Result (List String) Csv):

Csv.parse rawData |> Csv.Decode.decode myDecoder

Using lovasoa/elm-csv (which returns a plain Csv):

Csv.parse rawData |> Csv.Decode.decodeCsv myDecoder

You can define decoders based on field position or on header name. See examples in the docs.

About

Decode CSV records to types


Languages

Language:Elm 100.0%