-- * Constructors and accessors
deriving (Eq, Show, Typeable, Data)
instance NFData Value where
rnf (Number n) = case n of I i -> rnf i; D d -> rnf d
name .= value = (name, toJSON value)
+-- | Construct an optional 'Pair' from a key and a Maybe value. If
+-- the value is Nothing, then it is omitted altogether from the
+(.=?) :: ToJSON a => Text -> Maybe a -> Pair
+name .=? Nothing = (name, Missing)
+name .=? Just value = (name, toJSON value)
-- | Convert a value from JSON, failing if the types do not match.
fromJSON :: (FromJSON a) => Value -> Result a
fromJSON = parse parseJSON
-- | Create a 'Value' from a list of name\/value 'Pair's. If duplicate
-- keys arise, earlier keys and their associated values win.
object :: [Pair] -> Value
-object = Object . M.fromList
+object = Object . M.fromList . filter (notmissing . snd)
+ where notmissing Missing = False
-- | A type that can be converted to JSON.