Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eeue56/elm-json-field-value
https://github.com/eeue56/elm-json-field-value
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eeue56/elm-json-field-value
- Owner: eeue56
- License: bsd-3-clause
- Created: 2017-11-13T00:01:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-13T00:13:45.000Z (about 7 years ago)
- Last Synced: 2024-05-21T12:33:37.597Z (8 months ago)
- Language: Elm
- Size: 2.93 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```elm
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")```