@@ -28,11 +28,24 @@ module Data.Aeson
2828 , (.:)
2929 , (.:?)
3030 , object
31− -- * Encoding and parsing
31+ -- * Encoding and decoding
32+ , decode
3233 , encode
34+ -- * Parsing
3335 , json
3436 ) where
3537
3638import Data.Aeson.Encode
3739import Data.Aeson.Parser
3840import Data.Aeson.Types
41+import qualified Data.ByteString.Lazy as L
42+import qualified Data.Attoparsec.Lazy as L
43+
44+-- | Efficiently deserialize a JSON value from a lazy 'L.ByteString'.
45+decode :: (FromJSON a) => L.ByteString -> Maybe a
46+decode s = case L.parse json s of
47+ L.Done _ v -> case fromJSON v of
48+ Success a -> Just a
49+ _ -> Nothing
50+ _ -> Nothing
51+{-# INLINE decode #-}