@@ -1,3 +1,5 @@
2-- Module: Data.Aeson
4-- Module: Data.Aeson
3-- Copyright: (c) 2011-2016 Bryan O'Sullivan
5-- Copyright: (c) 2011-2016 Bryan O'Sullivan
@@ -120,6 +122,7 @@ module Data.Aeson
123 -- * Parsing
126 -- * Parsing
@@ -135,6 +138,7 @@ import Data.Aeson.Types
135import Data.Aeson.Types.Internal (JSONPath, formatError)
138import Data.Aeson.Types.Internal (JSONPath, formatError)
136import qualified Data.ByteString as B
139import qualified Data.ByteString as B
137import qualified Data.ByteString.Lazy as L
140import qualified Data.ByteString.Lazy as L
141+import qualified Data.Text.Encoding as T
139-- | Efficiently serialize a JSON value as a lazy 'L.ByteString'.
143-- | Efficiently serialize a JSON value as a lazy 'L.ByteString'.
@@ -220,6 +224,15 @@ eitherDecodeStrict' =
220 eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
224 eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
221{-# INLINE eitherDecodeStrict' #-}
225{-# INLINE eitherDecodeStrict' #-}
227+-- | Decode a nested JSON-encoded string.
228+embeddedJSON :: (FromJSON a) => String -> (Value -> Parser a)
229+embeddedJSON str = withText str (either fail return . eitherDecode . fromStrict . T.encodeUtf8)
231+#if MIN_VERSION_bytestring(0, 9, 2)
232+ fromStrict = L.fromChunks . (:[])
234+ fromStrict = L.fromStrict
225-- This section contains basic information on the different ways to
238-- This section contains basic information on the different ways to