File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE CPP #-}
2
+
1
3
-- |
2
4
-- Module: Data.Aeson
3
5
-- Copyright: (c) 2011-2016 Bryan O'Sullivan
@@ -120,6 +122,7 @@ module Data.Aeson
120
122
, (.:!)
121
123
, (.!=)
122
124
, object
125
+ , embeddedJSON
123
126
-- * Parsing
124
127
, json
125
128
, json'
@@ -135,6 +138,7 @@ import Data.Aeson.Types
135
138
import Data.Aeson.Types.Internal (JSONPath , formatError )
136
139
import qualified Data.ByteString as B
137
140
import qualified Data.ByteString.Lazy as L
141
+ import qualified Data.Text.Encoding as T
138
142
139
143
-- | Efficiently serialize a JSON value as a lazy 'L.ByteString'.
140
144
--
@@ -220,6 +224,15 @@ eitherDecodeStrict' =
220
224
eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON
221
225
{-# INLINE eitherDecodeStrict' #-}
222
226
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
223
236
-- $use
224
237
--
225
238
-- This section contains basic information on the different ways to
You can’t perform that action at this time.
0 commit comments