(require("json-stringify-raw"))(value, replaceropt, nullable, spaceopt, nullable) → {string}
Converts a given value to a JSON string, optionally using a given
replacer function and spacing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
* | Value to be converted to JSON. | |
replacer |
module:json-stringify-raw~replacerFunction | Array.<(string|number)> |
<optional> <nullable> |
Optional function to selectively replace values in the JSON, or array of property names which will be converted to JSON. |
space |
number | string |
<optional> <nullable> |
Number of spaces, or string added to each nesting level during output. If no indent is added, line breaks and spacing between elements is omitted. Indents are limited to 10 characters, negatives values are ignored. |
Throws:
-
-
If value contains circular references.
- Type
- TypeError
-
-
-
If value contains a bigint and BigInt.prototype.toJSON has not been defined.
- Type
- TypeError
-
-
-
If replacer returns a value which is not a stirng, boolean, null, or undefined.
- Type
- TypeError
-
Returns:
JSON for value, or undefined if not representable.
- Type
- string
Type Definitions
replacerFunction(key, value) → {string|boolean}
Function to selectively replace values in JSON output.
Called with
this
set to the object on which the value is a
property.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Name of property value to replace, or empty string for a value which was not passed as a property. |
value |
* | Value to replace. |
Returns:
A string which represents the value in the JSON,
a boolean to include or exclude the property from the JSON, or
null or undefined to indicate that the value should be
stringified normally, without replacement. Any other value will cause
TypeError to be thrown.
- Type
- string | boolean