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