Introduction to Elm, v2

Decoding JSON Exercise

Richard Feldman

Richard Feldman

Vendr, Inc.
Introduction to Elm, v2

Check out a free preview of the full Introduction to Elm, v2 course

The "Decoding JSON Exercise" Lesson is part of the full, Introduction to Elm, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Students use JSON decoding to read data from the server into the articles in the feed.


Transcript from the "Decoding JSON Exercise" Lesson

>> Richard Feldman: So for this exercise, we're going to see that there's something slightly wrong with our feed once again. This poor feed really can't catch a break. So on the left we see what we're going to see when we start out, which is to say that instead of actually showing the article names.

Because these are coming back as JSON from the server. It's just going to say needs decoding everywhere, because that's what we've hard-coded it to. And what we're going to do is we're going to actually implement the decoders that will translate that from the server. So that we can actually get our nice article titles back here, so I'll jump into part7 for that.

>> Richard Feldman: And-
>> Richard Feldman: If we open up the README, once again, we've got the same build command as before, articles don't quite look right. And the way we're going to fix this is by adding article.elm and resolving the TODO that's in there. So, this right here is a metadata decoder, it's decoding some metadata about the articles.

Which is to say things like the title and the description and all that. And we've got, as you can see, [LAUGH], required for createdAt, that's the only one that we actually have implemented. And all of the others are hardcoded, so hardcoded is something that happens in these pipeline decoders, if you say, you know what?

I don't even want to look at the JSON, just hardcode it to always be this value, and just stick that right there in the record. So what we're going to do is we're going to replace all of these calls to hardcoded. With calls to required in order to decode these things properly.

Okay, so that's the only to-do that we have to resolve. But of course it has multiple sub to-dos, because there are several instances of hardcoded here. But when they're all done, everything should compile, and the articles should be appearing in the feed again.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now