Empty string isn't valid JSON. Try open Chrome DevTools and write
JSON.parse("").

2016-05-17 14:51 GMT+06:00 Janis Voigtländer <janis.voigtlaen...@gmail.com>:

> See https://github.com/elm-lang/core/issues/585. Considered a bug.
> ​
>
> 2016-05-17 10:45 GMT+02:00 Richard Osafo <rich...@ritsoftgh.com>:
>
>> Hi,
>> I was decoding an http response (body can be blank) and realized that
>> Decode fails on empty string. Gives the error "Given an invalid JSON:
>> Syntax error". Is this by design or a bug?
>>
>>
>> import Html exposing (text)
>> import Json.Decode as Decode exposing (..)
>>
>>
>> main =
>>   text <| toString test
>>
>>
>> test =
>>   [ succeed "cool"
>>   , fail "oh"
>>   , null "what?"
>>   ]
>>   |> List.map (flip decodeString "")
>>
>>
>> If it is by design, what is the recommended way of decoding string that
>> can be blank.
>>
>> For now, I'm using
>>
>>     let
>>       x' =
>>         if x == "" then "\"\"" else x
>>     in
>>       case decodeString decoder x' of
>>         ...
>>
>>
>>
>> regards,
>> Richard.
>>
>> --
>> 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.
>>
>
> --
> 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.
>



-- 
Best regards,
Fedor Nezhivoi.

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