Created
August 13, 2017 17:18
-
-
Save arbaaz/0bda66dde30dadcca361c98490df8960 to your computer and use it in GitHub Desktop.
JSON decode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- json : String | |
-- json = | |
-- """ | |
-- { | |
-- "kind": "Listing", | |
-- "data": { | |
-- "children": [ | |
-- {"data":{"url":"http://www.example.com", "title":"hello"}}, | |
-- {"data":{"url": "http://www.example.com", "title":"world"}} | |
-- ] | |
-- } | |
-- } | |
-- """ | |
type alias Post = | |
{ url : String | |
, title : String | |
} | |
type alias PostList = | |
List Post | |
postDecoder : Decoder Post | |
postDecoder = | |
JD.map2 Post | |
(field "url" string) | |
(field "title" string) | |
-- postsDecoder : Decoder PostList | |
-- postsDecoder = | |
-- at [ "data", "children" ] <| | |
-- JD.list <| | |
-- at [ "data" ] postDecoder | |
postsDecoder : Decoder PostList | |
postsDecoder = | |
at [ "data" ] postDecoder | |
|> JD.list | |
|> at [ "data", "children" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment