Set default values while decoding JSON

It’s also possible to stick with map2 by replacing Location with a lambda function:

decodeLocations : Decoder (List Location)
decodeLocations =
    Dec.field "locations"
        (Dec.list
            (Dec.map2 (\id name -> { id = id, name = name, checked = True })
                (Dec.field "id" Dec.int)
                (Dec.field "name" Dec.string)
            )
        )
2 Likes