Skip to content

Instantly share code, notes, and snippets.

@alexspurling
Created November 10, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexspurling/e7173ceebb339e1b4bca to your computer and use it in GitHub Desktop.
Save alexspurling/e7173ceebb339e1b4bca to your computer and use it in GitHub Desktop.
Not sure how to complete these Json Decoder example.
type alias Answer =
{ name : String,
imgUrl : String
}
decodeAnswers : Json.Decoder (List Answer)
decodeAnswers =
let
imageUrlDecoder = ("url" := Json.string)
imagesDecoder = Json.list imageUrlDecoder --Decoder List String
firstImageDecoder = ??
albumDecoder = Json.object2 Answer ("name" := Json.string) firstImageDecoder
in
(Json.at ["albums", "items"] (Json.list albumDecoder))
{
"albums" : {
"href" : "https://api.spotify.com/v1/search?query=foo&offset=0&limit=20&type=album",
"items" : [ {
"album_type" : "compilation",
"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ],
"external_urls" : {
"spotify" : "https://open.spotify.com/album/1zCNrbPpz5OLSr6mSpPdKm"
},
"href" : "https://api.spotify.com/v1/albums/1zCNrbPpz5OLSr6mSpPdKm",
"id" : "1zCNrbPpz5OLSr6mSpPdKm",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/d181666ebeda1aa062a5f0250b85be6150badd0f",
"width" : 640
}, {
"height" : 300,
"url" : "https://i.scdn.co/image/9ed1dc82d30f1b519a97659f401c2397cfd68878",
"width" : 300
}, {
"height" : 64,
"url" : "https://i.scdn.co/image/e08a4a69c8c83ecf2437f15ba706db3f35106a6b",
"width" : 64
} ],
"name" : "Greatest Hits",
"type" : "album",
"uri" : "spotify:album:1zCNrbPpz5OLSr6mSpPdKm"
}, {
"album_type" : "album",
"available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ],
"external_urls" : {
"spotify" : "https://open.spotify.com/album/2qwN15acAl3sm3Idce5vK9"
},
"href" : "https://api.spotify.com/v1/albums/2qwN15acAl3sm3Idce5vK9",
"id" : "2qwN15acAl3sm3Idce5vK9",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/6366b355d9f5abe6a4b74c26486cec8877960b8a",
"width" : 640
}, {
"height" : 300,
"url" : "https://i.scdn.co/image/7cef7ca470cd0b2e07924f28f4eed8af65ad7a89",
"width" : 300
}, {
"height" : 64,
"url" : "https://i.scdn.co/image/4614809bd85219e78fdb5dd0d884cddef7f29f82",
"width" : 64
} ],
"name" : "Sonic Highways",
"type" : "album",
"uri" : "spotify:album:2qwN15acAl3sm3Idce5vK9"
}],
"limit" : 20,
"next" : "https://api.spotify.com/v1/search?query=foo&offset=20&limit=20&type=album",
"offset" : 0,
"previous" : null,
"total" : 330
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment