@@ -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(..)
@@ -40,7 +42,7 @@ module Data.Aeson
42import Data.Aeson.Encode (encode)
44import Data.Aeson.Encode (encode)
43−import Data.Aeson.Parser.Internal (decodeWith, json, json')
45+import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, json, json')
44import Data.Aeson.Types
46import Data.Aeson.Types
45import qualified Data.ByteString.Lazy as L
47import qualified Data.ByteString.Lazy as L
@@ -63,3 +65,13 @@ decode = decodeWith json fromJSON
63decode' :: (FromJSON a) => L.ByteString -> Maybe a
65decode' :: (FromJSON a) => L.ByteString -> Maybe a
64decode' = decodeWith json' fromJSON
66decode' = decodeWith json' fromJSON
65{-# INLINE decode' #-}
67{-# INLINE decode' #-}
69+-- | Like 'decode' but returns an error message when decoding fails.
70+eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
71+eitherDecode = eitherDecodeWith json fromJSON
72+{-# INLINE eitherDecode #-}
74+-- | Like 'decode'' but returns an error message when decoding fails.
75+eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
76+eitherDecode' = eitherDecodeWith json' fromJSON
77+{-# INLINE eitherDecode' #-}