@Janis
Thanks. It is the same issue. Not a show stopper though since a simple `if`
fixes it.
@Fedor
Indeed but in that case, don't you think Json.Decode.succeed and
Json.Decode.fail must be updated to point that out? When you do `oneOf`
with `succeed` in it, you naturally expect it to work as that is what the
documentation says.
On Tuesday, May 17, 2016 at 8:54:08 AM UTC, Fedor Nezhivoi wrote:
> 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 <[email protected]
> <javascript:>>:
>
>> See https://github.com/elm-lang/core/issues/585. Considered a bug.
>>
>>
>> 2016-05-17 10:45 GMT+02:00 Richard Osafo <[email protected]
>> <javascript:>>:
>>
>>> 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 [email protected] <javascript:>.
>>> 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 [email protected] <javascript:>.
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.