Skip to content

Commit

Permalink
Add stringifyWithIndent (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
srghma authored Sep 9, 2020
1 parent 5ad5251 commit 6b17010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Data/Argonaut/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ exports.stringify = function (j) {
return JSON.stringify(j);
};

exports.stringifyWithIndent = function (i) {
return function (j) {
return JSON.stringify(j, null, i);
};
};

function isArray(a) {
return Object.prototype.toString.call(a) === "[object Array]";
}
Expand Down
12 changes: 9 additions & 3 deletions src/Data/Argonaut/Core.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Data.Argonaut.Core
, jsonEmptyObject
, jsonSingletonObject
, stringify
, stringifyWithIndent
) where

import Prelude
Expand Down Expand Up @@ -178,13 +179,13 @@ toObject = toJsonType caseJsonObject

-- Encoding

-- | Construct `Json` from a `Boolean` value
-- | Construct `Json` from a `Boolean` value
foreign import fromBoolean :: Boolean -> Json

-- | Construct `Json` from a `Number` value
-- | Construct `Json` from a `Number` value
foreign import fromNumber :: Number -> Json

-- | Construct `Json` from a `String` value. If you would like to parse a string
-- | Construct `Json` from a `String` value. If you would like to parse a string
-- | of JSON into valid `Json`, see `jsonParser`.
foreign import fromString :: String -> Json

Expand Down Expand Up @@ -235,6 +236,11 @@ jsonSingletonObject key val = fromObject (Obj.singleton key val)
-- | string value, see `fromString`.
foreign import stringify :: Json -> String

-- | Converts a `Json` value to a JSON string.
-- | The first `Int` argument specifies the amount of white space characters to use as indentation.
-- | 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.
foreign import stringifyWithIndent :: Int -> Json -> String

foreign import _caseJson
:: forall z
. Fn7
Expand Down

0 comments on commit 6b17010

Please sign in to comment.