A playground for decoding a JSON object in elm.
One thing that threw me with decoding a JSON response was that you have to know what the response is before you can decode it.
To my knowledge, unlike JavaScript you can't seem to blurt out the complete response of a Http request to a console or whatever - and then decide what parts you need.
It's no biggie. If you're unsure of the structure of your response, try using something like Postman or Paw.
The following examples are using the same endpoint yet decoding different levels of data in the responses. I've also included an example on handling a Http.Error.
https://api.myjson.com/bins/yws2
{
"title": "This is an amazing title",
"data": [
{
"id": 1,
"name": "foo"
},
{
"id": 2,
"name": "bar"
},
{
"id": 3,
"name": "baz"
}
],
"obj": {
"title": "I'm a nested object"
},
"members": [
{
"id": 4,
"name": "garply",
"profile": {
"avatar": "some_path_to_garply"
}
},
{
"id": 5,
"name": "waldo",
"profile": {
"avatar": "some_path_to_waldo"
}
},
{
"id": 6,
"name": "fred",
"profile": {
"avatar": "some_path_to_fred"
}
}
]
}
chrisbuttery.com · GitHub @chrisbuttery · Twitter @buttahz · elm-lang slack @butters