on master help sign in
Make the comment on `.:!` more accurate.
45d241bIan Grant Jeffries
Data/Aeson/Types/FromJSON.hs+9−5
@@ -655,9 +655,9 @@ obj .: key = case H.lookup key obj of
655 Just v -> parseJSON v <?> Key key
655 Just v -> parseJSON v <?> Key key
656{-# INLINE (.:) #-}
656{-# INLINE (.:) #-}
657
657
658−-- | Retrieve the value associated with the given key of an 'Object'. The
658+-- | Retrieve the value associated with the given key of an 'Object'. The
659−-- result is 'Nothing' if the key is not present or value is 'Null', or 'empty'
659+-- result is 'Nothing' if the key is not present or if its value is 'Null',
660−-- if the value cannot be converted to the desired type.
660+-- or 'empty' if the value cannot be converted to the desired type.
661--
661--
662-- This accessor is most useful if the key and value can be absent
662-- This accessor is most useful if the key and value can be absent
663-- from an object without affecting its validity. If the key and
663-- from an object without affecting its validity. If the key and
@@ -668,8 +668,12 @@ obj .:? key = case H.lookup key obj of
668 Just v -> parseJSON v <?> Key key
668 Just v -> parseJSON v <?> Key key
669{-# INLINE (.:?) #-}
669{-# INLINE (.:?) #-}
670
670
671−-- | Like '.:?', but the resulting parser will fail,
671+-- | Retrieve the value associated with the given key of an 'Object'.
672−-- if the key is present but is 'Null'.
672+-- The result is 'Nothing' if the key is not present or 'empty' if the
673+-- value cannot be converted to the desired type.
674+--
675+-- This differs from '.:?' by attempting to parse 'Null' the same as any
676+-- other JSON value, instead of interpreting it as 'Nothing'.
673(.:!) :: (FromJSON a) => Object -> Text -> Parser (Maybe a)
677(.:!) :: (FromJSON a) => Object -> Text -> Parser (Maybe a)
674obj .:! key = case H.lookup key obj of
678obj .:! key = case H.lookup key obj of
675 Nothing -> pure Nothing
679 Nothing -> pure Nothing