packages feed

aeson-combinators 0.1.0.1 → 0.1.1.0

raw patch · 4 files changed

+34/−5 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Aeson.Combinators.Decode: fromDecoder :: Decoder a -> Value -> Parser a
+ Data.Aeson.Combinators.Decode: maybeKey :: Key -> Decoder a -> Decoder (Maybe a)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for aeson-combinators +## 0.1.1.0 -- 2023-09-03+* `fromDecoder` utility to unwrap a `Decoder`'s function+* `maybeKey` combinator+ ## 0.1.0.1 -- 2022-05-03 * fix benchmark compatibility with ghc 9.2.2 
README.md view
@@ -1,6 +1,5 @@ # Aeson Combinators -[![Build Status](https://travis-ci.org/turboMaCk/aeson-combinators.svg?branch=master)](https://travis-ci.org/turboMaCk/aeson-combinators) [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FturboMaCk%2Faeson-combinators%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/turboMaCk/aeson-combinators/goto?ref=master) [![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org) 
aeson-combinators.cabal view
@@ -1,6 +1,6 @@ cabal-version:       >=1.10 name:                aeson-combinators-version:             0.1.0.1+version:             0.1.1.0 synopsis:            Aeson combinators for dead simple JSON decoding description:     Low overhead value space `Decoder`@@ -21,8 +21,7 @@ tested-with:         GHC == 8.8.4                    , GHC == 8.10.7                    , GHC == 9.0.2-                   , GHC == 9.2.1-                   , GHC == 9.2.2+                   , GHC == 9.2.5                    , GHCJS == 8.6.0.1  Flag doctest
lib/Data/Aeson/Combinators/Decode.hs view
@@ -27,6 +27,7 @@   -- $applicative     Decoder(..)   , auto+  , fromDecoder -- * Decoding Containers -- *** Maybe   , nullable@@ -40,6 +41,7 @@   , jsonNull -- *** Objects   , key+  , maybeKey   , at -- *** Arrays   , index@@ -92,7 +94,7 @@   ) where  import           Prelude                    hiding (either, fail, maybe)-import qualified Prelude                    (either)+import qualified Prelude                    (either, maybe)  import           Control.Applicative import           Control.Monad              hiding (void)@@ -303,6 +305,17 @@   {-# INLINE fail #-}  +-- | Conversely, an Aeson's 'FromJSON' instance can be implemented by using 'Decoder' combinators.+--+-- > newtype People = People [Person]+-- >+-- > instance FromJSON People where+-- >     parseJSON = fromDecoder $ Decode.list personDecoder+fromDecoder :: Decoder a -> Value -> Parser a+fromDecoder (Decoder f) = f+{-# INLINE fromDecoder #-}++ -- | 'Decoder' is compatible with Aeson's 'FromJSON' class. -- 'auto' decoder acts like a proxy to instance implementation. -- Any type that is an instance of this class is automatically compatible.@@ -413,6 +426,20 @@   Object v -> d =<< v .: t   val      -> typeMismatch "Object" val {-# INLINE key #-}++-- | Same as 'key' but works with omitted attributes in payloads and produces parsed values in the context of 'Maybe'.+--   Note that this combinator behaves differently to a combination of 'maybe' and 'key', which produce error if+--   the attribute is missing from the json object.+-- >>> decode (maybeKey "data" int) "{}"+-- Just Nothing+--+--- >>> decode (maybeKey "data" int) "{\"data\": 42}"+-- Just (Just 42)+maybeKey :: Key -> Decoder a -> Decoder (Maybe a)+maybeKey t (Decoder d) = Decoder $ \case+  Object v -> (v .:? t) >>= Prelude.maybe (pure Nothing) (fmap Just . d)+  val      -> typeMismatch "Object" val+{-# INLINE maybeKey #-}   -- | Extract JSON value from JSON object keys