Hi,

I have the following json that i want to Decode :

{
...
"otherAttr" : 123,
"city1" : "",
"city2" : "Cupertino",
"yetAnotherAttr" : 123,
...
}

Here's my target model  :


type alias User = 
{...
, otherAttr : Int,
, city : String       
, yetAnotherAttr : Int,
...
}



I want city to be decoded from city1 if present and fallback to city2, do 
you have any clue?

So far i've tried using Decoder.oneOf then Decoder.at without success


userDecoder : Decoder User
userDecoder =
    decode user
        |> ...
        |> required "otherAttr" int
        |> cityDecoder
        |> required "yetAnotherAttr" int
        |> ...

cityDecoder : Decoder String
cityDecoder = 
    Decode.at [ "city1", "city2" ] Decode.string        -- Not working !!




Any help appreciated!

Cheers,
Mehdi 

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to