From e4e033acaa9fb8895c02de1730a4f2fe96fdca08 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Tue, 22 Dec 2015 15:54:46 +0000 Subject: [PATCH] Decode null as Nothing in decodeJsonMaybe --- src/Data/Argonaut/Decode.purs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Data/Argonaut/Decode.purs b/src/Data/Argonaut/Decode.purs index d093643..180d908 100644 --- a/src/Data/Argonaut/Decode.purs +++ b/src/Data/Argonaut/Decode.purs @@ -10,7 +10,7 @@ import Prelude import Control.Alt ((<|>)) import Control.Bind ((=<<)) -import Data.Argonaut.Core (Json(), foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toNumber, toObject, toString, toBoolean) +import Data.Argonaut.Core (Json(), isNull, foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toNumber, toObject, toString, toBoolean) import Data.Array (zipWithA) import Data.Either (either, Either(..)) import Data.Foldable (find) @@ -65,7 +65,9 @@ gDecodeJson' signature json = case signature of mFail msg = maybe (Left msg) Right instance decodeJsonMaybe :: (DecodeJson a) => DecodeJson (Maybe a) where - decodeJson j = (Just <$> decodeJson j) <|> pure Nothing + decodeJson j + | isNull j = pure Nothing + | otherwise = (Just <$> decodeJson j) <|> (pure Nothing) instance decodeJsonTuple :: (DecodeJson a, DecodeJson b) => DecodeJson (Tuple a b) where decodeJson j = decodeJson j >>= f