Hi all,

I'm tryind to parse Reddit JSON <#> but I think I'm failing at the
Json.Decoder— however I'm not sure if that really is the problem, and I
don't know what else to try.

The (ugly) JSON has this format (not so ugly after cleaned up, BTW):

{
  "data": {
    "children": [
      {
        "data": {
          "title": "Post title",
          "url": "http://po.st/url";,
          "domain": "po.st",
          …
        },
        …
      },
      …
    ],
    …
  }
  …}

I want to parse the title, url and domain inside data.children[i].data
(where i stands for each element of the list/array) in news list from my
Elm model:

type alias NewsItem =
    { title : String
    , url : String
    , domain : String
    }
type alias Model =
    { news : List NewsItem }

I've tried this without success:

decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
    Json.object3 NewsItem
        (Json.at ["data", "title"] Json.string)
        (Json.at ["data", "url"] Json.string)
        (Json.at ["data", "domain"] Json.string)
decodeNews : Json.Decoder (List NewsItem)decodeNews =
    Json.at ["data", "chidren"] (Json.list decodeNewsItem)

The compiler throws no error at all, but once I open it (either with
elm-reactor or the HTML from elm-make) the screen is blank (no errors, but
no posts actually loaded from Reddit):

What am I doing wrong? The full Elm script, with Task and init is here <#>.

Many thanks,

Eduardo Cuducos
http://cuducos.me <#>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to