Looks like you already have Date and not String.

I am pretty new to Elm myself and I couldn't find a way to decodeValue of 
Date, but, I think as a workaround, on JavaScript side before sending the json 
through port, you could convert your Date fields to String with: 

myJson.date = myJson.date.toISOString()

Hope it helps.


On Sunday, January 29, 2017 at 4:55:51 PM UTC+2, fxmy wang wrote:
>
> Hi guys,
> So I was trying to decode a field named date inside JSON as String but 
> without success. And the result is quite confusing.
> Could anyone shed some light on me?
>
> JSON:
>
> [{"author":{"type":"full","displayName":"fxmy","url":"https://github.com/fxmy","picture":"https://avatars.githubusercontent.com/u/3283415?v=3&s=73"},"content":"another
>  test","date":"2017-01-26T03:43:57.190Z"}]
>
> Json.Encode.Value that comes through port ( via Debug.log) :
>
> value: { 0 = { author = { type = "full", displayName = "fxmy", url = 
> "https://github.com/fxmy";, picture = 
> "https://avatars.githubusercontent.com/u/3283415?v=3&s=73"; }, content = 
> "another test", date = <Thu Jan 26 2017 11:43:57 GMT+0800 (CST)> } }
>
> When trying to decode date field as String I got this,
> Result after calling Json.Decode.decodeValue ( via Debug.log) :
>
> Err "Expecting a String at _[0].date but instead got: 
> \"2017-01-26T03:43:57.190Z\""
>
> What am I doing wrong?
>
> Cheers.
> ​
>

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