Skip to content

Commit

Permalink
Add missing null handling:
Browse files Browse the repository at this point in the history
  • Loading branch information
tolysz committed Jan 15, 2016
1 parent 81f8fb5 commit c1a7cad
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Data/Aeson/Types/Instances.hs
Expand Up @@ -1613,9 +1613,10 @@ obj .: key = case H.lookup key obj of
-- value are mandatory, use '.:' instead.
(.:?) :: (FromJSON a) => Object -> Text -> Parser (Maybe a)
obj .:? key = case H.lookup key obj of
Nothing -> pure Nothing
Just v -> modifyFailure addKeyName
$ parseJSON v <?> Key key
Nothing -> pure Nothing
Just Null -> pure Nothing
Just v -> modifyFailure addKeyName
$ Just <$> parseJSON v <?> Key key
where
addKeyName = (("failed to parse field " <> unpack key <> ": ") <>)
{-# INLINE (.:?) #-}
Expand Down

0 comments on commit c1a7cad

Please sign in to comment.