Convenience functions for working with Json
Can be helpful when decoding large objects incrementally.
import Date (Date)
type alias User =
{ id : Int
, createdAt : Date
, updatedAt : Date
, deletedAt : Maybe Date
, username : Maybe String
, email : Maybe String
, fullname : Maybe String
, fullnamePrivate : Bool
, stripeId : Maybe String
, edaTools : Maybe String
, avatar : Maybe String
, isModerator : Bool
, isOrganization : Bool
, isAdmin : Bool
}
metaDecoder : (Int -> Date -> Date -> Maybe Date -> b) -> Decoder b
metaDecoder f = f
`map` ("id" := int)
`andApply` ("createdAt" := date)
`andApply` ("updatedAt" := date)
`andApply` ("deletedAt" := maybe date)
userDecoder : Decoder User
userDecoder = metaDecoder User
`andApply` ("username" := maybe string)
`andApply` ("email" := maybe string)
`andApply` ("fullname" := maybe string)
`andApply` ("fullnamePrivate" := bool)
`andApply` ("stripeId" := maybe string)
`andApply` ("edaTools" := maybe string)
`andApply` ("avatar" := maybe string)
`andApply` ("isModerator" := bool)
`andApply` ("isOrganization" := bool)
`andApply` ("isAdmin" := bool)
Extract a date.
Note that this function is not total, it will throw an exception given an incorrectly formatted date. See 'Date.fromString' and 'Json.customDecoder'.