@@ -37,12 +37,16 @@ module Data.Aeson
38 , eitherDecode
38 , eitherDecode
39 , eitherDecode'
39 , eitherDecode'
41 -- ** Variants for strict bytestrings
43 -- ** Variants for strict bytestrings
42 , decodeStrict
44 , decodeStrict
43 , decodeStrict'
45 , decodeStrict'
44 , eitherDecodeStrict
46 , eitherDecodeStrict
45 , eitherDecodeStrict'
47 , eitherDecodeStrict'
48+ , verboseDecodeStrict
49+ , verboseDecodeStrict'
46 -- * Core JSON types
50 -- * Core JSON types
47 , Value(..)
51 , Value(..)
48 , Encoding
52 , Encoding
@@ -131,9 +135,14 @@ import Prelude.Compat
132import Data.Aeson.Types.FromJSON (ifromJSON)
136import Data.Aeson.Types.FromJSON (ifromJSON)
133import Data.Aeson.Encoding (encodingToLazyByteString)
137import Data.Aeson.Encoding (encodingToLazyByteString)
138+import Data.Aeson.Parser.Internal
139+ ( decodeWith, decodeStrictWith
134−import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith, eitherDecodeWith, eitherDecodeStrictWith, jsonEOF, json, jsonEOF', json')
140+ , eitherDecodeWith, eitherDecodeStrictWith
141+ , verboseDecodeWith, verboseDecodeStrictWith
142+ , jsonEOF, json, jsonEOF', json')
135import Data.Aeson.Types
143import Data.Aeson.Types
136−import Data.Aeson.Types.Internal (JSONPath, formatError)
144+import Data.Aeson.Types.Internal (JSONPath, formatError, formatErrors)
145+import Data.List.NonEmpty (NonEmpty)
137import qualified Data.ByteString as B
146import qualified Data.ByteString as B
138import qualified Data.ByteString.Lazy as L
147import qualified Data.ByteString.Lazy as L
@@ -221,6 +230,35 @@ eitherDecodeStrict' =
221 eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
230 eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
222{-# INLINE eitherDecodeStrict' #-}
231{-# INLINE eitherDecodeStrict' #-}
234+ :: Either (NonEmpty (JSONPath, String)) a -> Either (NonEmpty String) a
235+eitherFormatErrors = either (Left . formatErrors) Right
236+{-# INLINE eitherFormatErrors #-}
238+-- | Like 'decode' but returns one or more error messages when decoding fails.
239+verboseDecode :: (FromJSON a) => L.ByteString -> Either (NonEmpty String) a
240+verboseDecode = eitherFormatErrors . verboseDecodeWith jsonEOF ifromJSON
241+{-# INLINE verboseDecode #-}
243+-- | Like 'decodeStrict' but returns one or more error messages when decoding
245+verboseDecodeStrict :: (FromJSON a) => B.ByteString -> Either (NonEmpty String) a
246+verboseDecodeStrict =
247+ eitherFormatErrors . verboseDecodeStrictWith jsonEOF ifromJSON
248+{-# INLINE verboseDecodeStrict #-}
250+-- | Like 'decode'' but returns one or more error messages when decoding fails.
251+verboseDecode' :: (FromJSON a) => L.ByteString -> Either (NonEmpty String) a
252+verboseDecode' = eitherFormatErrors . verboseDecodeWith jsonEOF' ifromJSON
253+{-# INLINE verboseDecode' #-}
255+-- | Like 'decodeStrict'' but returns one or more error messages when decoding
257+verboseDecodeStrict' :: (FromJSON a) => B.ByteString -> Either (NonEmpty String) a
258+verboseDecodeStrict' =
259+ eitherFormatErrors . verboseDecodeStrictWith jsonEOF' ifromJSON
260+{-# INLINE verboseDecodeStrict' #-}
226-- This section contains basic information on the different ways to
264-- This section contains basic information on the different ways to