Skip to content

ericgj/elm-csv-decode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages