Skip to content
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

Decoder error even-though it's correct #26

Open
empeje opened this issue Oct 19, 2020 · 0 comments
Open

Decoder error even-though it's correct #26

empeje opened this issue Oct 19, 2020 · 0 comments

Comments

@empeje
Copy link

empeje commented Oct 19, 2020

I have the following Type called Message with the following code

module Types.Message exposing (Message, decode, decodeList)

import Json.Decode as Decode exposing (Decoder, Error, list)
import Json.Decode.Pipeline exposing (required)


type alias Message =
    { username : String
    , content : String
    }


decode : Decoder Message
decode =
    Decode.succeed Message
        |> required "username" Decode.string
        |> required "content" Decode.string

decodeList : Decoder (List Message)
decodeList =
    list decode

I try to decode using something like this

decodeMessage : Decode.Value -> Result Error (List Message)
decodeMessage messageJson =
    Decode.decodeValue
        Message.decodeList
        messageJson

I found out that it works perfectly in REPL

> decodeString decode "{\"username\": \"mantap\", \"content\": \"lalui\"}"
Ok { content = "lalui", username = "mantap" }
    : Result Error Message

However, when I run the Webpack build using the elm-webpack-loader in Electron environment I found the following error

Problem with the value at json[0]: "{\"content\": \"Budi\", \"username\": \"UHU\"}" Expecting an OBJECT with a field named `content`

Any idea why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant