The following code can be found in a demo here: https://ellie-app.com/mbFwJT9jD3/0
import Html exposing (..)
import Json.Decode exposing (Decoder)
payload =
"""
[{
"id": 0,
"name": "Adam Carter",
"work": "Unilogic",
"email": "[email protected]",
"dob": "24/11/1978",
"address": "83 Warner Street",
"city": "Boston",
"optedin": true
},
{
"id": 1,
"name": "Leanne Brier",
"work": "Connic",
"email": "[email protected]",
"dob": "13/05/1987",
"address": "9 Coleman Avenue",
"city": "Toronto",
"optedin": false
}]
"""
type alias User =
{ name: String
, work: String
, email: String
, dob: String
, address: String
, city: String
, optedin: Bool
}
main =
Json.Decode.decodeString decoder payload
|> toString
|> text
decoder: Decoder (List User)
decoder =
Json.Decode.map7 User
(Json.Decode.field "name" Json.Decode.string)
(Json.Decode.field "work" Json.Decode.string)
(Json.Decode.field "email" Json.Decode.string)
(Json.Decode.field "dob" Json.Decode.string)
(Json.Decode.field "address" Json.Decode.string)
(Json.Decode.field "city" Json.Decode.string)
(Json.Decode.field "optedin" Json.Decode.bool)
|> Json.Decode.list