Hi all,

Thanks again for all your help. And when I've asked questions last year.

I have another question. Here's my situation. I want to pass a json from a 
port, and decode the json into records. 

My port:

port parseSuccess : (Json.Encode.Value -> msg) -> Sub msg


When calling it:

app.ports.parseSuccess.send(JSON.stringify(cst.toAst()))

The recursive record:

type alias Node = {
>     name : String
>   , children : Children
>   }
>
> type Children =
>   Children (List Node)


The fromJson to decode the Json.

fromJson : Json.Value -> Result String Node
> fromJson json =
>     Json.decodeValue nodeDecoder json
>

My decoders:

nodeDecoder : Decoder Node
> nodeDecoder =
>   object2 Node
>     ("name" := string)
>     ("children" := childrenDecoder )
>
 

childrenDecoder : Decoder Children
> childrenDecoder =
>   customDecoder
>     (Json.list nodeDecoder)
>     (\children -> Result.Ok <| Children children)


When I run it, I get an error in the Result in "fromJson"
: Err "Expecting an object with a field named `name` but instead got: 
\"{\\\"name\\\":\\\"WhereClause\\\",\\\"children\\\":[{\\\"name\\\":\\\"ComparisonPredicate\\\",\\\"children\\\":[\\\"age\\\",{\\\"name\\\":\\\"ComparisonPredicatePart2\\\",\\\"children\\\":[\\\"<\\\",\\\"10\\\"]}]}]}\""

What's the difference between Json.Encoder.Value and a String? When I'm 
calling the port on the JS side, I'm sending a string from 
JSON.stringify(). It seems like it comes in as Json.Encoder.Value as the 
type, but according to the error, it seems like it's coming in as a string. 
What am I doing wrong?

Wil


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