Created
October 17, 2016 22:13
-
-
Save svoynow/39f3b6c2d68a078c3347193a2ee882b0 to your computer and use it in GitHub Desktop.
This file contains 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 Json.Decode exposing (list, int, string, null, float, Decoder, object2, (:=), at, oneOf) | |
import Json.Decode.Pipeline exposing (decode, required, custom, requiredAt) | |
-- trying to get rid of this | |
type alias NetworksContainer = | |
{ | |
networks : List Network | |
} | |
-- decoders | |
networkListDecoder : Decoder (List Network) | |
networkListDecoder = | |
list networkDecoder | |
-- this is a hack to un-nest the JSON structure | |
-- I'm sure there's a better way.. | |
networksDecoder : Decoder (List Network) | |
networksDecoder = | |
Json.Decode.map .networks | |
(decode NetworksContainer | |
|> required "networks" networkListDecoder) | |
networkDecoder : Decoder Network | |
networkDecoder = | |
decode Network | |
|> required "name" string |
This file contains 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
{"networks": [ | |
{"name" : "foo"}, | |
{"name" : "bar"}, | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment