# Decoder generator and imports cleanup tool

**URL:** <https://discourse.elm-lang.org/t/decoder-generator-and-imports-cleanup-tool/1399>\
**Category:** Show and Tell\
**Created:** [June 19, 2018, 11:07am UTC](https://discourse.elm-lang.org/t/decoder-generator-and-imports-cleanup-tool/1399 "2018-06-19T11:07:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![joelq](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/joelq/32/445_2.png) [@joelq](https://discourse.elm-lang.org/u/joelq)\
**Post date:** [June 19, 2018, 2:42pm UTC](https://discourse.elm-lang.org/t/decoder-generator-and-imports-cleanup-tool/1399/2 "2018-06-19T14:42:04Z")

</div>

I like the look and feel of it! I threw a bunch of types at the decoder generator to see what it could handle 😆. I’m impressed 💯 !

It handles:

- ✅ Records
- ✅ Tuples
- ✅ Dicts
- ✅ Lists
- ✅ Nested structures like a list of tuples
- ✅ Sum types (e.g. `type Color = Red | Green | Blue`)

I’ve noticed is struggles with product types like `type Email = Email String`. If I were writing this by hand I’d implement the decoder as this one-liner:

```elm
decodeEmail =
  Dec.map Email Dec.string

```

but the generator attempts to decode it using a huge nested case and multiple calls to `decodeValue` 😰

```elm
decodeEmail =
   let
      recover xs =
         case xs of
            a0::bs->
               case decodeValue Dec.string a0 of
                  Ok "Email"->
                     case bs of
                        a1::cs ->
                              case decodeValue Dec.string a1 of
                                 Ok a1_->
                                    Dec.succeed <| Email a1_
                                 Err err->
                                    Dec.fail err
                        _->
                           Dec.fail <| "Invalid fields for constructor Email: " ++ toString bs
                  Ok other->
                     Dec.fail <| "Invalid constructor field found: " ++ other
                  Err err->
                     Dec.fail err
            _->
               Dec.fail "Invalid JSON input: empty list"
   in
      Dec.list Dec.value |> andThen recover

```

---

_[View the full topic](https://discourse.elm-lang.org/t/decoder-generator-and-imports-cleanup-tool/1399)._
