This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Json decoder helpers for dealign with complex values
version 1.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.0
Committed At 2017-11-13 00:13:28 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

README

elm-json-field-value

This package is intended to make it easier to work with complicated JSON decoders suitable for parsing ASTs from JSON in Elm.

Install


elm-package install --yes eeue56/elm-json-field-value

Usage


import Json.Decode
import Json.Decode.FieldValue exposing (fieldValue)

type Animal = Dog | Cat

decodeAnimal : Json.Decode.Decoder Animal
decodeAnimal = 
    Json.Decode.oneOf
        [ decodeDog
        , decodeCat
        ]

decodeDog : Json.Decode.Decoder Animal
decodeDog =
    Json.Decode.map (\_ -> Dog)
        (Json.Decode.field "type" <| fieldValue "dog")

decodeCat : Json.Decode.Decoder Animal
decodeCat =
    Json.Decode.map (\_ -> Cat)
        (Json.Decode.field "type" <| fieldValue "cat")