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

Decoding a Maybe-value #8

k-bx opened this Issue Nov 4, 2018 · 2 comments


None yet
2 participants

k-bx commented Nov 4, 2018


I'm using elm-bridge to generate decoders and encoders with Elm 0.19 and json-helpers 2.0.0.

Maybe-value parsing is failing for me. I can show the full code that's generated from elm-bridge, but here I've recreated the essence:

module Main exposing (main)                                                                                                                                                                                                                                                                                          
import Browser                                                                                                                                                                                                                                                                                                       
import Html exposing (..)                                                                                                                                                                                                                                                                                            
import Json.Decode as Decode                                                                                                                                                                                                                                                                                         
import Json.Helpers as JsonHelpers                                                                                                                                                                                                                                                                                   
type alias Model =                                                                                                                                                                                                                                                                                                   
type alias Msg =                                                                                                                                                                                                                                                                                                     
type alias Foo =                                                                                                                                                                                                                                                                                                     
    { foo : Maybe Int }                                                                                                                                                                                                                                                                                              
view _ =                                                                                                                                                                                                                                                                                                             
        jsonDecFoo : Decode.Decoder Foo                                                                                                                                                                                                                                                                              
        jsonDecFoo =                                                                                                                                                                                                                                                                                                 
            Decode.succeed (\pfoo -> { foo = pfoo })                                                                                                                                                                                                                                                                 
                |> JsonHelpers.fnullable "foo"                                                                                                                                                                                                                                                            
        decodeResult =                                                                                                                                                                                                                                                                                               
            Decode.decodeString jsonDecFoo "{\"foo\": null}"                                                                                                                                                                                                                                                         
    case decodeResult of                                                                                                                                                                                                                                                                                             
        Ok val ->                                                                                                                                                                                                                                                                                                    
            text "ok"                                                                                                                                                                                                                                                                                                
        Err err ->                                                                                                                                                                                                                                                                                                   
            text ("not ok: " ++ Decode.errorToString err)                                                                                                                                                                                                                                                            
main : Program () Model Msg                                                                                                                                                                                                                                                                                          
main =                                                                                                                                                                                                                                                                                                               
        { init = ()                                                                                                                                                                                                                                                                                                  
        , view = view                                                                                                                                                                                                                                                                                                
        , update = \x y -> y                                                                                                                                                                                                                                                                                         

Full repo which can be built is at

The error I get is:

not ok: Json.Decode.oneOf failed in the following 2 ways: (1) Problem with the given value: { "foo": null } Expecting null (2) Problem with the value at null Expecting an INT

Help appreciated!

@k-bx k-bx referenced this issue Nov 4, 2018


Fix fnullable #9

@bartavelle bartavelle closed this in 550f45d Nov 6, 2018


This comment has been minimized.


bartavelle commented Nov 6, 2018

reopen, there is a bug in elm-bridge


This comment has been minimized.

k-bx commented Nov 6, 2018

Hmm, there's no button to reopen. Please make a new issue if needed! (as I'm not sure what's the bug exactly)

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