@@ -1,3 +1,5 @@
1+{-# LANGUAGE CPP #-}
2+
13-- |
24-- Module: Data.Aeson
35-- Copyright: (c) 2011-2016 Bryan O'Sullivan
@@ -120,6 +122,7 @@ module Data.Aeson
120122 , (.:!)
121123 , (.!=)
122124 , object
125+ , embeddedJSON
123126 -- * Parsing
124127 , json
125128 , json'
@@ -135,6 +138,7 @@ import Data.Aeson.Types
135138import Data.Aeson.Types.Internal (JSONPath, formatError)
136139import qualified Data.ByteString as B
137140import qualified Data.ByteString.Lazy as L
141+import qualified Data.Text.Encoding as T
138142
139143-- | Efficiently serialize a JSON value as a lazy 'L.ByteString'.
140144--
@@ -220,6 +224,15 @@ eitherDecodeStrict' =
220224 eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
221225{-# INLINE eitherDecodeStrict' #-}
222226
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)
230+ where
231+#if MIN_VERSION_bytestring(0, 9, 2)
232+ fromStrict = L.fromChunks . (:[])
233+#else
234+ fromStrict = L.fromStrict
235+#endif
223236-- $use
224237--
225238-- This section contains basic information on the different ways to