elm-community / json-extra / Json.Encode.Extra

Convenience functions for turning Elm values into Json values.

maybe : (a -> Json.Encode.Value) -> Maybe a -> Json.Encode.Value

Encode a Maybe value. If the value is Nothing it will be encoded as null

import Json.Encode exposing (..)


maybe int (Just 50)
--> int 50


maybe int Nothing
--> null