Skip to content

Instantly share code, notes, and snippets.

@rohanorton
Last active May 9, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohanorton/d21a9a55d94223837c0de329f2bfb000 to your computer and use it in GitHub Desktop.
Save rohanorton/d21a9a55d94223837c0de329f2bfb000 to your computer and use it in GitHub Desktop.
optional "note" string ""
optional "note" (map Just string) Nothing
optional "note" (map (\x -> if x == "" then Nothing else Just x) string) Nothing
import Json.Encode as Json
type alias NotePayload = { notes : Maybe String }
-- { "notes": "abc" }
encodeNotePayload : NotePayload -> Value
encodeNotePayload payload =
Json.object [ ("notes", encodeMaybeString payload.notes ) ]
encodeMaybeString : Maybe String -> Value
encodeMaybeString maybeString =
case maybeString of
Nothing -> Json.null
Just str -> Json.string str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment