@@ -16,6 +16,8 @@ module Data.Aeson
16 -- * Encoding and decoding
16 -- * Encoding and decoding
20 -- * Core JSON types
22 -- * Core JSON types
21 , Value(..)
23 , Value(..)
@@ -46,7 +48,7 @@ module Data.Aeson
48import Data.Aeson.Encode (encode)
50import Data.Aeson.Encode (encode)
49−import Data.Aeson.Parser.Internal (decodeWith, json, json')
51+import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, json, json')
50import Data.Aeson.Types
52import Data.Aeson.Types
51import qualified Data.ByteString.Lazy as L
53import qualified Data.ByteString.Lazy as L
@@ -69,3 +71,13 @@ decode = decodeWith json fromJSON
69decode' :: (FromJSON a) => L.ByteString -> Maybe a
71decode' :: (FromJSON a) => L.ByteString -> Maybe a
70decode' = decodeWith json' fromJSON
72decode' = decodeWith json' fromJSON
71{-# INLINE decode' #-}
73{-# INLINE decode' #-}
75+-- | Like 'decode' but returns an error message when decoding fails.
76+eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
77+eitherDecode = eitherDecodeWith json fromJSON
78+{-# INLINE eitherDecode #-}
80+-- | Like 'decode'' but returns an error message when decoding fails.
81+eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
82+eitherDecode' = eitherDecodeWith json' fromJSON
83+{-# INLINE eitherDecode' #-}