# Set default values while decoding JSON

**URL:** <https://discourse.elm-lang.org/t/set-default-values-while-decoding-json/6387>\
**Category:** Learn\
**Created:** [October 9, 2020, 9:06pm UTC](https://discourse.elm-lang.org/t/set-default-values-while-decoding-json/6387 "2020-10-09T21:06:45Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![lydell](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lydell/32/178_2.png) [@lydell](https://discourse.elm-lang.org/u/lydell)\
**Post date:** [October 10, 2020, 12:07am UTC](https://discourse.elm-lang.org/t/set-default-values-while-decoding-json/6387/3 "2020-10-10T00:07:52Z")

</div>

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

```auto
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)
            )
        )

```

---

_[View the full topic](https://discourse.elm-lang.org/t/set-default-values-while-decoding-json/6387)._
