Source

aeson / Data / Aeson.hs

Diff from to

Data/Aeson.hs

     -- * Encoding and decoding
       decode
     , decode'
+    , eitherDecode
+    , eitherDecode'
     , encode
     -- * Core JSON types
     , Value(..)
     , Result(..)
     , fromJSON
     , ToJSON(..)
+    -- * Inspecting @'Value's@
+    , withObject
+    , withText
+    , withArray
+    , withNumber
+    , withBool
     -- * Constructors and accessors
     , (.=)
     , (.:)
     ) where
 
 import Data.Aeson.Encode (encode)
-import Data.Aeson.Parser.Internal (decodeWith, json, json')
+import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, json, json')
 import Data.Aeson.Types
 import qualified Data.ByteString.Lazy as L
 
 decode' :: (FromJSON a) => L.ByteString -> Maybe a
 decode' = decodeWith json' fromJSON
 {-# INLINE decode' #-}
+
+-- | Like 'decode' but returns an error message when decoding fails.
+eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
+eitherDecode = eitherDecodeWith json fromJSON
+{-# INLINE eitherDecode #-}
+
+-- | Like 'decode'' but returns an error message when decoding fails.
+eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
+eitherDecode' = eitherDecodeWith json' fromJSON
+{-# INLINE eitherDecode' #-}