New blog post: You could have designed the Json.Decode library!

At elm-conf I had a weird idea about writing a universal JSON decoder that decoded JSON into a generic JsonValue type. I noodled with it for a while and realized that my experimentation didn’t yield any crazy new tech but did help me understand why Json.Decoder works the way it does better than anything I’d seen previously. I just published a blog post that explains what I learned: https://dev.to/matthewsj/you-could-have-designed-the-jsondecode-library-2d8 I’d love to hear what you think about it!

17 Likes

I think this is a great in-depth answer to the question you mention in the beginning (“why is Json.Decode so confusing?”), and also does a great job of showing the logical process to arrive at the API.

The one suggestion I’d have is that the article is quite long–does dev.to have a way to add a table of contents?

Also, I’m curious if there were other APIs for this that you originally tried to implement which you initially thought might be a nicer API but weren’t possible to implement. If so, I’d be interested to see a small section showing why some of those things didn’t work (or maybe in a future blog post).

Good work!
I’m working on the closed-source SPA than will be open-sourced soon.
In this application, I am working with exactly this JSON-like structure because I need to work with unstructured user defined JSON and JSON-schema (format it, merge, modify, etc).
I implemented collapsable json view, custom pretty print, and implementing json-path (xpath like) function on top of it. So there are some cases where Json.Decode is not the best solution.
In my case, the described structure works very well.

Very nice article in all aspects :clap: I learnt and discovered a lot.

I think this is a great resource for people struggling with decoders. For example I never really stopped to think about the definition of the type Decoder, even if I had been using it . Seeing the type alias with the examples has made the pieces of knowledge and usage click together, thanks a lot.

I just want to say: You’re a lifesaver! With the help of your blogpost, I’ve finally been able to completely refactor my own decoding library (that decodes hexadecimal Ethereum ABI requests and responses); the decoders are finally composable.

For anyone who hasn’t read this article yet: It’s really worth the time!

As promised half year ago :slight_smile:
My “universal” json parser, edit functions, renderer and collapsible interactive viewer
https://github.com/zalando-incubator/nakadi-ui/blob/master/client/Helpers/JsonEditor.elm