Created
September 2, 2015 18:30
-
-
Save amitaibu/26fed3040f8664ff36db to your computer and use it in GitHub Desktop.
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
import Graphics.Element exposing (show) | |
import Json.Decode as Json exposing ((:=)) | |
-- MODEL | |
type alias Model = | |
{ id: Int | |
, label: String | |
} | |
serialized : String | |
serialized = "{\"id\":1,\"label\":\"foo\"}" | |
decoder : Json.Decoder Model | |
decoder = | |
Json.object2 Model | |
("id" := Json.int) | |
-- Notice instead of label we have a "wrongKey" | |
("wrongKey" := Json.string) | |
main = | |
show (Json.decodeString decoder serialized) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment