- 23 May 2023
-
DarkLight
-
PDF
objectToString
- Updated on 23 May 2023
-
DarkLight
-
PDF
objectToString Task Purpose
The objectToString task is used to convert any valid JSON value to a JSON string. In contrast to parse, this task method returns a string representation of a JSON value.
Potential Use Cases
You could use objectToString as a formatting method to display content that is readable in a web browser. This task could also be used for logging or any other circumstance where you need to render a JSON object contextually as a string in a readable format.
Properties
Input and output properties are shown below.
Input | Type | Description |
---|---|---|
value |
* | Required. Any valid JSON value to convert to a JSON string. |
replacer |
Array | Optional. An array of string and number objects that serve as an allowlist (whitelist) for selecting/filtering the properties of the value object to be included in the JSON string. If this value is not provided, all properties of the object are included in the resulting JSON string. |
space |
Number | Optional. A number from 0 to 10 to indicate how many whitespaces (or space characters) to insert in the output JSON string. This parameter is used for readability purposes to control spacing in the final string. |
Output | Type | Description |
---|---|---|
stringified |
String | A JSON string representing the given value . |
Example 1
In the example shown below, the incoming value
is statically set. The replacer
value (filtering property) is "city"
, and the number of space
characters to insert is 2.
Example 2
In this example, the replacer
values are "age"
and "city"
.
Example 3
In this example, all properties of the object are included in the resulting JSON string.