Skip to content

Commit e4e033a

Browse files
committed
Decode null as Nothing in decodeJsonMaybe
1 parent f0b9994 commit e4e033a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Data/Argonaut/Decode.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Prelude
1010

1111
import Control.Alt ((<|>))
1212
import Control.Bind ((=<<))
13-
import Data.Argonaut.Core (Json(), foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toNumber, toObject, toString, toBoolean)
13+
import Data.Argonaut.Core (Json(), isNull, foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toNumber, toObject, toString, toBoolean)
1414
import Data.Array (zipWithA)
1515
import Data.Either (either, Either(..))
1616
import Data.Foldable (find)
@@ -65,7 +65,9 @@ gDecodeJson' signature json = case signature of
6565
mFail msg = maybe (Left msg) Right
6666

6767
instance decodeJsonMaybe :: (DecodeJson a) => DecodeJson (Maybe a) where
68-
decodeJson j = (Just <$> decodeJson j) <|> pure Nothing
68+
decodeJson j
69+
| isNull j = pure Nothing
70+
| otherwise = (Just <$> decodeJson j) <|> (pure Nothing)
6971

7072
instance decodeJsonTuple :: (DecodeJson a, DecodeJson b) => DecodeJson (Tuple a b) where
7173
decodeJson j = decodeJson j >>= f

0 commit comments

Comments
 (0)