# Elm Radio Episode 4 - JSON Decoders

**URL:** <https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661>\
**Category:** Show and Tell\
**Created:** [April 27, 2020, 3:37pm UTC](https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661 "2020-04-27T15:37:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dillonkearns](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dillonkearns/32/1587_2.png) [@dillonkearns](https://discourse.elm-lang.org/u/dillonkearns)\
**Post date:** [April 27, 2020, 3:37pm UTC](https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661/1 "2020-04-27T15:37:42Z")

</div>

Episode 4 is out! We hope you find it useful. I think we lay out some useful points if you’re getting started with JSON decoders. And we get into some best practices and concepts for more advanced Elm developers as well.

> **[Episode 4: JSON Decoders](https://elm-radio.com/episode/json-decoders/)**
>
> We discuss the basics of JSON Decoders, benefits compared to JSON in JavaScript, best practices, and how to get started learning.

---

<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:** [April 28, 2020, 6:13pm UTC](https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661/2 "2020-04-28T18:13:57Z")

</div>

I liked the part about optional fields and the where to put the `Json.Decode.maybe`. Here’s an easy way to remember how to do it: Use [Json.Decode.Extra.optionalNullableField](https://package.elm-lang.org/packages/elm-community/json-extra/latest/Json-Decode-Extra#optionalNullableField). Hot take: `Json.Decode.maybe` is never useful.

---

<div class="post-metadata">

**Author:** ![dillonkearns](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dillonkearns/32/1587_2.png) [@dillonkearns](https://discourse.elm-lang.org/u/dillonkearns)\
**Post date:** [May 1, 2020, 2:57am UTC](https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661/3 "2020-05-01T02:57:49Z")

</div>

Great point @lydell!

You’re right that if you use `Json.Decode.maybe` it will cover up some cases that you may not have intended to. I didn’t really consider this, but you’re absolutely right!

```elm
import Json.Decode as Decode

""" {"temperatureInF": 86} """ |> Decode.decodeString (Decode.maybe (Decode.field "temperatureInF" Decode.int))
--> Ok (Just 86)

""" {"temperatureInF": 86.14} """ |> Decode.decodeString (Decode.maybe (Decode.field "temperatureInF" Decode.int))
--> Ok Nothing

```

In many cases, if you’re allowing the field to be null or absent, you would still want to know if it’s present but the decoder fails. I bet that’s tripped some people up. I wish I was aware of `Json.Decode.Extra.optionalNullableField` when we recorded that episode! ~~I’ll update the show notes with a reference to this, though~~ Update: I [updated the show notes](https://github.com/dillonkearns/elm-radio.com/commit/81ff15f9b741b5901297cc4300246b8f3d8dedd8?short_path=bfecd5a#diff-bfecd5a42ef9d64c9c13611e5a6a1f87)! 😄

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 11, 2020, 2:57am UTC](https://discourse.elm-lang.org/t/elm-radio-episode-4-json-decoders/5661/4 "2020-05-11T02:57:52Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
