Figured it out! My approach was to use keyValuePairs, but instead of 
defining one Decoder, I defined oneOf Decoder-s with one Decoder a and one 
succeed. This way I will get default value returned for count, which 
represents no problem in the end, and actual values retuned by Decoder a. 
Once mixing them up it should work properly.

-- Code:

import Json.Decode exposing (..)

-- empty list is returned because I care about List String values, not Int 
and empty list 
--  will make no difference

keyValuePairs (oneOf [ decoder , succeed [] ])






Dne sreda, 20. julij 2016 14.41.09 UTC+2 je oseba Matic Zavadlal napisala:
>
> Hi! 
>
> I am trying to resolve some json data, whose structure looks like this:
>
> {
>   "count": Int,
>   "a": List String,
>   "b": List String,
>   "c": List String
> }
>
> So, as you see, one variable has type of Int and all the others have the 
> same type, in this example it's a list string.
> Because number of "other" variables differs I can't use objectN decoder to 
> resolve this. I tried with keyValuePairs
> combined with oneOf, but because oneOf takes list as an argument Decoders 
> of list value type and value type can't be
> combined. 
>
> How should I solve this?
>

-- 
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