O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Safely Decode JSON

Prior to this point, you’ve been able to stay safely within the confines of Elm’s magical world of static types. However, you’re going to run into an interesting dilemma if you want to accept an arbitrary JSON payload from a server. Elm doesn’t have a JSON.parse function like JavaScript because it can’t dynamically create records like JavaScript can create objects. In this section, you’re going to learn about JSON decoders, why they’re important, and how to use them to safely convert JSON into a static type Elm can use.

Understand the Problem

To understand why you need JSON decoders, let’s look at a couple of example JSON payloads you could use with your application. Visit https://programming-elm.com/feed/1 in your browser. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required