# JSON Decode package for decoding objects

**URL:** <https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469>\
**Category:** Show and Tell\
**Created:** [November 7, 2018, 9:19am UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469 "2018-11-07T09:19:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertdahlin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/albertdahlin/32/868_2.png) [@albertdahlin](https://discourse.elm-lang.org/u/albertdahlin)\
**Post date:** [November 7, 2018, 9:19am UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/1 "2018-11-07T09:19:08Z")

</div>

I just published a package for building JSON decoders using continuation style (chains of functions). I hope someone finds it useful.

[webbhuset/elm-json-decode](https://package.elm-lang.org/packages/webbhuset/elm-json-decode/latest/)

This is the result of some converstions in [this thread](https://discourse.elm-lang.org/t/experimental-json-decoding-api/2121) aswell as feedback from our Elm meetups.

Thank to @rtfeldman for helping out with documentation and ideas.

---

<div class="post-metadata">

**Author:** ![Deimos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/deimos/32/2359_2.png) [@Deimos](https://discourse.elm-lang.org/u/Deimos)\
**Post date:** [November 8, 2018, 5:17am UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/2 "2018-11-08T05:17:44Z")

</div>

Looks great! I like the way you get access to the data before building the object. Even though the syntax is longer than elm pipeline decoder, I think it’s more flexible. Thanks!

---

<div class="post-metadata">

**Author:** ![malaire](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@malaire](https://discourse.elm-lang.org/u/malaire)\
**Post date:** [November 8, 2018, 7:09pm UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/3 "2018-11-08T19:09:05Z")

</div>

I’m trying to install this with `elm install webbhuset/elm-json-decode` but get error about corrupt ZIP:

```
I got an unexpected zip file from:

    <https://github.com/webbhuset/elm-json-decode/zipball/1.0.0/>

I check the hash the zip, and it seems off:

  Expected: bdb9648731f8824f8d7d2df3378449d133dc0b2f
    Actual: d4a81c47a40c53d597b340284ab7bb0c7e22810a

This usually means that the package author moved the version tag, so report it
to them and see if that is the issue. Folks on Elm slack can probably help as
well.
```

---

<div class="post-metadata">

**Author:** ![albertdahlin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/albertdahlin/32/868_2.png) [@albertdahlin](https://discourse.elm-lang.org/u/albertdahlin)\
**Post date:** [November 8, 2018, 9:13pm UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/4 "2018-11-08T21:13:37Z")

</div>

Hmm, that is strange. Thank you for reporting. I will look into this.

---

<div class="post-metadata">

**Author:** ![albertdahlin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/albertdahlin/32/868_2.png) [@albertdahlin](https://discourse.elm-lang.org/u/albertdahlin)\
**Post date:** [November 9, 2018, 6:08am UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/5 "2018-11-09T06:08:01Z")

</div>

I could reproduce this when I cleared `~/.elm`. I didn’t think about that when I tested after publishing yesterday so it worked fine.

I created the tag `1.0.0` and then ran `elm publish`. It failed due to a missing LICENSE file.  
I added the license file, commited and moved the tag to the new commit. I then ran `elm publish` again and it succeeded.

Probably it was wrong of me to assume that it was OK to move a tag when `elm publish` failed?

@malaire I bumped to 1.0.1 and it works now, thanks for reporting.

---

<div class="post-metadata">

**Author:** ![1hko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/1hko/32/1328_2.png) [@1hko](https://discourse.elm-lang.org/u/1hko)\
**Post date:** [November 9, 2018, 5:34pm UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/6 "2018-11-09T17:34:41Z")

</div>

What’s the likelihood Elm would ever see a `do` syntax? It would make the API a lot nicer – especially with the recent removal of user-defined infix functions

```auto
person : Decoder Person
person = do
    name <- Field.require "name" Decode.string
    id <- Field.require "id" Decode.int
    maybeWeight <- Field.attempt "weight" Decode.int
    maybeLikes <- Field.attempt "likes" Decode.int

    Decode.succeed
        { name = name
        , id = id
        , maybeWeight = maybeWeight
        , likes = Maybe.withDefault 0 maybeLikes
        , hardcoded = "Hardcoded Value"
        }

```

---

<div class="post-metadata">

**Author:** ![brasilikum](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/brasilikum/32/524_2.png) [@brasilikum](https://discourse.elm-lang.org/u/brasilikum)\
**Post date:** [November 10, 2018, 5:36pm UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/7 "2018-11-10T17:36:32Z")

</div>

I love this! It made immediately more sense to me than any other way to decode json. Thank you very much!

---

<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:** [November 20, 2018, 5:36pm UTC](https://discourse.elm-lang.org/t/json-decode-package-for-decoding-objects/2469/8 "2018-11-20T17:36:41Z")

</div>

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