Skip to content

eike/json-decode-complete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package allows you to write decoders for JSON objects that make sure that you handled all fields of the incoming JSON. For example,

import Json.Decode as D exposing (Decoder)
import DecodeComplete exposing (..)

type alias User =
    { name : String
    , age : Int
    }

userDecoder : Decoder User
userDecoder =
    object User
        |> require "name" D.string
        |> require "age" D.int
        |> discard "email"
        |> complete

decodes JSON objects that have precisely the fields name, age, and email and turns it into a User record, discarding the email address.

These decoders are turned into regular Decoders at the end, so that they can be used with normal elm/json code.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages