# Prevent Impossible States with JSON Decoders in Elm

**URL:** <https://discourse.elm-lang.org/t/prevent-impossible-states-with-json-decoders-in-elm/2573>\
**Category:** Show and Tell\
**Created:** [November 21, 2018, 12:53am UTC](https://discourse.elm-lang.org/t/prevent-impossible-states-with-json-decoders-in-elm/2573 "2018-11-21T00:53:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinyank](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/kevinyank/32/241_2.png) [@kevinyank](https://discourse.elm-lang.org/u/kevinyank)\
**Post date:** [November 21, 2018, 12:53am UTC](https://discourse.elm-lang.org/t/prevent-impossible-states-with-json-decoders-in-elm/2573/1 "2018-11-21T00:53:18Z")

</div>

> **[Decoding JSON in Elm preventing impossible states. – Julio Feijo – Medium](https://medium.com/@send.to.julio/decoding-json-in-elm-preventing-impossible-states-2c1c34f1f7f6)**
>
> When we receive JSON values, there is often a risk of introducing impsd

---

<div class="post-metadata">

**Author:** ![andys8](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/andys8/32/280_2.png) [@andys8](https://discourse.elm-lang.org/u/andys8)\
**Post date:** [November 21, 2018, 10:14pm UTC](https://discourse.elm-lang.org/t/prevent-impossible-states-with-json-decoders-in-elm/2573/2 "2018-11-21T22:14:39Z")

</div>

The part how it proposes to do the decoding with different constructors of a custom type is interesting.

In general the problem is the typical problem, how to encode tagged sum types in languages that don’t have them. In this case json. What `status` is in this example is often called `kind` or `type`. See [https://github.com/gcanti/fp-ts/blob/master/fp-ts-for-purescripters.md#data](https://github.com/gcanti/fp-ts/blob/master/fp-ts-for-purescripters.md#data)

---

<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:** [December 1, 2018, 10:14pm UTC](https://discourse.elm-lang.org/t/prevent-impossible-states-with-json-decoders-in-elm/2573/3 "2018-12-01T22:14:46Z")

</div>

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