Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 720 Bytes

README.md

File metadata and controls

23 lines (18 loc) · 720 Bytes

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.