On Thursday, December 1, 2016 at 12:32:39 PM UTC, Rupert Smith wrote:
>
> Seems that for some reason where I was previously decoding a List encoded 
> Dict as json as the value associated with the event, a String is now 
> expected.
>
>  value = Object {ctor: "Err", _0: "Expecting a String at _.detail.value[0] 
> but instead got: ["1","auth-root"]"}
>

Turns out it was my json encoders and decoders at fault, as they did not 
encode and decode the same json.

decodeItems : Decode.Decoder (List ( String, String ))
decodeItems =
    Decode.at [ "detail", "value" ] <|
        Decode.list <|
            Decode.map2 (,) Decode.string Decode.string
 
encodeItems : List ( String, String ) -> Encode.Value
encodeItems items =
    Encode.list
        (List.map (\( idx, val ) -> Encode.list [ Encode.string idx, 
Encode.string val ]) items)

I changed the decoder to:

decodeItems : Decode.Decoder (List ( String, String ))
decodeItems =
    Decode.at [ "detail", "value" ] <|
        Decode.list <|
            Decode.map2 (,) (Decode.index 0 Decode.string) (Decode.index 1 
Decode.string)

and it works. I seem to have opted for a slightly non-standard encoding of 
a dictionary as an array of arrays, rather than as a json object with 
name/value fields, but I can fix that.

Strange that it worked in 0.17, I guess the json parsing rules got 
tightened up a bit.
 

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to