Json.Decode.Extra is a set of “Convenience functions for working with Json”. It adds functions that you’ll find yourself in need of when doing more advanced work with Json and Elm. Elm’s default Json.Decode
library is pretty good but has some shortcomings.
Examples
Main.elm
$ elm-package install elm-community/json-extra
import Json.Decode.Extra as Extra exposing ((|:))
metaDataDecoder : Decoder MetaData
metaDataDecoder =
Json.Decode.map MetaData ("username" := JD.string)
|: ("lastPlayedAt" := Extra.date)
|: ("url" := JD.string)
|: ("bank" := JD.float)
|: ("lastBetSize" := betDecoder)
betDecoder : Decoder (Maybe Float)
betDecoder =
Json.Decode.float |> Extra.withDefault 0.0
Links