Skip to content

Decode null as Nothing in decodeJsonMaybe #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Data/Argonaut/Decode.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down