@@ -37,6 +37,8 @@ module Data.Argonaut.Core
37
37
, jsonEmptyObject
38
38
, jsonSingletonObject
39
39
, stringify
40
+ , stringifyWith
41
+ , stringifyWithSpace
40
42
) where
41
43
42
44
import Prelude
@@ -45,6 +47,7 @@ import Data.Function.Uncurried (Fn5, runFn5, Fn7, runFn7)
45
47
import Data.Maybe (Maybe (..))
46
48
import Foreign.Object (Object )
47
49
import Foreign.Object as Obj
50
+ import Unsafe.Coerce (unsafeCoerce )
48
51
49
52
-- | The type of JSON data. The underlying representation is the same as what
50
53
-- | would be returned from JavaScript's `JSON.parse` function; that is,
@@ -178,13 +181,13 @@ toObject = toJsonType caseJsonObject
178
181
179
182
-- Encoding
180
183
181
- -- | Construct `Json` from a `Boolean` value
184
+ -- | Construct `Json` from a `Boolean` value
182
185
foreign import fromBoolean :: Boolean -> Json
183
186
184
- -- | Construct `Json` from a `Number` value
187
+ -- | Construct `Json` from a `Number` value
185
188
foreign import fromNumber :: Number -> Json
186
189
187
- -- | Construct `Json` from a `String` value. If you would like to parse a string
190
+ -- | Construct `Json` from a `String` value. If you would like to parse a string
188
191
-- | of JSON into valid `Json`, see `jsonParser`.
189
192
foreign import fromString :: String -> Json
190
193
@@ -235,6 +238,17 @@ jsonSingletonObject key val = fromObject (Obj.singleton key val)
235
238
-- | string value, see `fromString`.
236
239
foreign import stringify :: Json -> String
237
240
241
+ -- | Converts a `Json` value to a JSON string.
242
+ -- | The first `Int` argument specifies the amount of white space characters to use as indentation.
243
+ -- | This number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.
244
+ stringifyWithSpace :: Int -> Json -> String
245
+ stringifyWithSpace = unsafeCoerce stringifyWith
246
+
247
+ -- | Converts a `Json` value to a JSON string.
248
+ -- | The first `String` argument is used as indentation.
249
+ -- | If string is longer than 10 characters - only the first 10 characters are used.
250
+ foreign import stringifyWith :: String -> Json -> String
251
+
238
252
foreign import _caseJson
239
253
:: forall z
240
254
. Fn7
0 commit comments