New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json.Decode.decodeString never succeeds when input is empty string #585

Closed
jinjor opened this Issue May 2, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@jinjor
Contributor

jinjor commented May 2, 2016

For SSCCE:

import Html exposing (Html, text)
import Json.Decode as Json exposing (Decoder)

main : Html
main = text <| toString <| Json.decodeString decoder ""

decoder : Decoder String
decoder =
  Json.succeed "Succeed!"

This shows:

Err ("Unexpected end of input")

I ran into this problem when I used Http.post and tried to decode response (which is empty string). This issue may be related to this issue.

@jinjor jinjor changed the title from Json.Decode never succeeds when input is empty string to Json.Decode.decodeString never succeeds when input is empty string May 2, 2016

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender May 18, 2016

Contributor

It was noted on the mailing list that this is not a bug, but instead the expected behavior, since the emtpy string is not valid JSON.

Contributor

jvoigtlaender commented May 18, 2016

It was noted on the mailing list that this is not a bug, but instead the expected behavior, since the emtpy string is not valid JSON.

@jinjor

This comment has been minimized.

Show comment
Hide comment
@jinjor

jinjor May 19, 2016

Contributor

Ah, now I understand. Thank you.
The real problem here was "I assumed Json.Decode.succeed always succeeds even if given JSON is invalid", but it was wrong.

Contributor

jinjor commented May 19, 2016

Ah, now I understand. Thank you.
The real problem here was "I assumed Json.Decode.succeed always succeeds even if given JSON is invalid", but it was wrong.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender May 19, 2016

Contributor

I think the documentation could be more helpful, to prevent such misunderstandings. I opened https://github.com/elm-lang/core/issues/613.

Contributor

jvoigtlaender commented May 19, 2016

I think the documentation could be more helpful, to prevent such misunderstandings. I opened https://github.com/elm-lang/core/issues/613.

@jinjor

This comment has been minimized.

Show comment
Hide comment
@jinjor

jinjor May 19, 2016

Contributor

Seems good :)

Contributor

jinjor commented May 19, 2016

Seems good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment