Javascript to Elm

12: Fetch & Decoding JSON Part-2

Informações:

Sinopsis

  Finally Decoding But first if we google Elm decoding json, we get these gems Decoding Cheatsheet json decoding in elm is still hard The Json.Decode.decodeString function returns a Result. It has a type of: decodeString : Decoder val -> String -> Result String val so what does that mean? Well, more or less that we need Json.Decode to convert the JSON values into Elm values. And by elm values I mean, types safe, friendly compiler, you are there when I assume you are, and if not, it’s handled accordingly by type values. Json.Decode exposing (..) gives us primitives bool, float, int, string, and null. > decodeString bool "true" Ok True : Result.Result String Bool > decodeString bool "false" Ok False : Result.Result String Bool So Json.Decode has a ‘list’ function that Decoder and a(value) and returns a Decoder of (List a) > import Json.Decode exposing (list, bool, string, int) > list : Json.Decode.Decoder a -> Json.Decode.Decoder (List a) > bool : Json.Decode.Decoder Bool > string : J