Skip to content

Instantly share code, notes, and snippets.

@svoynow
Created October 17, 2016 22:13
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 svoynow/39f3b6c2d68a078c3347193a2ee882b0 to your computer and use it in GitHub Desktop.
Save svoynow/39f3b6c2d68a078c3347193a2ee882b0 to your computer and use it in GitHub Desktop.
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
{"networks": [
{"name" : "foo"},
{"name" : "bar"},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment