krisajenkins / elm-exts / Exts.Json.Decode

Extensions to the core Json.Decode library.

stringIgnoringBlanks : Json.Decode.Decoder (Maybe String)

A decoder like (maybe string), except an empty or whitespace string is treated as Nothing.

Useful for dirty data-models.

decodeTime : Json.Decode.Decoder Time.Posix

Decode a Date from seconds-since-the-epoch.

parseWith : (a -> Result String b) -> a -> Json.Decode.Decoder b

DEPRECATED: Use customDecoder instead.

Lift a function that parses things, returning a Result, into the world of decoders.

If you're looking for the pre-0.18 function customDecoder, you can use something like this instead:

decodeUUID : Decoder UUID
decodeUUID =
    string
        |> andThen (parseWith UUID.fromString)

customDecoder : Json.Decode.Decoder a -> (a -> Result String b) -> Json.Decode.Decoder b

Combine a primitive decoder and a parser to make a more sophisticated decoder.

set : Json.Decode.Decoder comparable -> Json.Decode.Decoder (Set comparable)

Decode a JSON array of things directly into a Set.

exactlyOne : Json.Decode.Decoder a -> Json.Decode.Decoder a

Expects a list where exactly one element will succeed with the given decoder.

decodeEmptyObject : a -> Json.Decode.Decoder a

Decode the empty object as the value given, and fail otherwise.