@@ -40,6 +40,11 @@ module Data.Aeson
40 , eitherDecode
40 , eitherDecode
41 , eitherDecode'
41 , eitherDecode'
43+ -- ** Variants for strict bytestrings
47+ , eitherDecodeStrict'
43 -- * Core JSON types
48 -- * Core JSON types
44 , Value(..)
49 , Value(..)
@@ -76,9 +81,11 @@ module Data.Aeson
78import Data.Aeson.Encode (encode)
83import Data.Aeson.Encode (encode)
79−import Data.Aeson.Parser.Internal (decodeWith, eitherDecodeWith, jsonEOF, json,
84+import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
85+ eitherDecodeWith, eitherDecodeStrictWith,
80− jsonEOF', json')
86+ jsonEOF, json, jsonEOF', json')
81import Data.Aeson.Types
87import Data.Aeson.Types
88+import qualified Data.ByteString as B
82import qualified Data.ByteString.Lazy as L
89import qualified Data.ByteString.Lazy as L
84-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
91-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
@@ -97,6 +104,19 @@ decode :: (FromJSON a) => L.ByteString -> Maybe a
97decode = decodeWith jsonEOF fromJSON
104decode = decodeWith jsonEOF fromJSON
98{-# INLINE decode #-}
105{-# INLINE decode #-}
107+-- | Efficiently deserialize a JSON value from a strict 'B.ByteString'.
108+-- If this fails due to incomplete or invalid input, 'Nothing' is
111+-- The input must consist solely of a JSON document, with no trailing
112+-- data except for whitespace.
114+-- This function parses immediately, but defers conversion. See
115+-- 'json' for details.
116+decodeStrict :: (FromJSON a) => B.ByteString -> Maybe a
117+decodeStrict = decodeStrictWith jsonEOF fromJSON
118+{-# INLINE decodeStrict #-}
100-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
120-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
101-- If this fails due to incomplete or invalid input, 'Nothing' is
121-- If this fails due to incomplete or invalid input, 'Nothing' is
102-- returned.
122-- returned.
@@ -113,16 +133,39 @@ decode' :: (FromJSON a) => L.ByteString -> Maybe a
113decode' = decodeWith jsonEOF' fromJSON
133decode' = decodeWith jsonEOF' fromJSON
114{-# INLINE decode' #-}
134{-# INLINE decode' #-}
136+-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
137+-- If this fails due to incomplete or invalid input, 'Nothing' is
140+-- The input must consist solely of a JSON document, with no trailing
141+-- data except for whitespace.
143+-- This function parses and performs conversion immediately. See
144+-- 'json'' for details.
145+decodeStrict' :: (FromJSON a) => B.ByteString -> Maybe a
146+decodeStrict' = decodeStrictWith jsonEOF' fromJSON
147+{-# INLINE decodeStrict' #-}
116-- | Like 'decode' but returns an error message when decoding fails.
149-- | Like 'decode' but returns an error message when decoding fails.
117eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
150eitherDecode :: (FromJSON a) => L.ByteString -> Either String a
118eitherDecode = eitherDecodeWith jsonEOF fromJSON
151eitherDecode = eitherDecodeWith jsonEOF fromJSON
119{-# INLINE eitherDecode #-}
152{-# INLINE eitherDecode #-}
154+-- | Like 'decodeStrict' but returns an error message when decoding fails.
155+eitherDecodeStrict :: (FromJSON a) => B.ByteString -> Either String a
156+eitherDecodeStrict = eitherDecodeStrictWith jsonEOF fromJSON
157+{-# INLINE eitherDecodeStrict #-}
121-- | Like 'decode'' but returns an error message when decoding fails.
159-- | Like 'decode'' but returns an error message when decoding fails.
122eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
160eitherDecode' :: (FromJSON a) => L.ByteString -> Either String a
123eitherDecode' = eitherDecodeWith jsonEOF' fromJSON
161eitherDecode' = eitherDecodeWith jsonEOF' fromJSON
124{-# INLINE eitherDecode' #-}
162{-# INLINE eitherDecode' #-}
164+-- | Like 'decodeStrict'' but returns an error message when decoding fails.
165+eitherDecodeStrict' :: (FromJSON a) => B.ByteString -> Either String a
166+eitherDecodeStrict' = eitherDecodeStrictWith jsonEOF' fromJSON
167+{-# INLINE eitherDecodeStrict' #-}
128-- This section contains basic information on the different ways to
171-- This section contains basic information on the different ways to