JSON Builder step
Summarize
Summary of JSON Builder step
The JSON Builder step in Workflow Studio enables you to create a JSON payload dynamically for use in subsequent workflow steps. It supports various data types including strings, numbers, booleans, objects, and arrays, allowing for nested JSON structures. This step requires an Integration Hub subscription and the appropriate plugin activation to be available.
Show less
Inputs
You define the payload by specifying name-value pairs with the following configurable inputs:
- Name: The key in the JSON pair, accepts static values or dynamic data pills.
- Value: The corresponding value, which can be a simple type or a complex object pill. Note that using a complex object pill replaces any children elements.
- Type: Data type of the value, chosen from String, Object, Number, Boolean, or Array. Nested objects or arrays can be built by adding name-value pairs within them.
- In case of empty value: Configures handling of empty or null values with options to keep as empty string, omit the property, set as null, or throw an error.
- Include Outer Structure: Option to include curly braces for the top-level JSON container.
- Omit Empty Structure: Option to omit the entire payload if it results in empty content based on empty value handling.
Outputs
The step produces the following outputs accessible via the Data panel for use in later action steps:
- Output: The generated JSON payload as a string. To use it as an object, pass it to a JSON parser step.
- Step Status: An object containing runtime details, including:
- Code: Integer indicating success (0) or error (1).
- Message: Error message if the step fails.
Additional Features
The step includes an Add JSON for Payload button that opens a script editor for automatic JSON payload generation. Key points for this feature:
- Automatically deserializes entered JSON into structured inputs.
- Handles empty keys, but duplicate keys are overridden by the last occurrence.
- If the root is an array, it is wrapped into a root object; keys from multiple objects in an array are combined.
- Does not support empty payloads, non-complex object types, invalid JSON, empty root objects, or payloads larger than 65,000 bytes.
- Generating a JSON payload via this method will overwrite any existing structure in the step.
Practical Considerations for ServiceNow Customers
This step is ideal when you need to construct complex JSON payloads dynamically within workflows, especially when integrating with external systems via Integration Hub. It provides fine control over payload structure and empty value handling, reducing the need for manual JSON scripting. The outputs facilitate easy chaining with other steps, such as JSON parsing or API calls.
Create a JSON payload to use in another step. Enter values or use data pills to produce a dynamic payload. This step supports several data types, including objects and arrays for nested structures.
Roles and availability
This step requires an Integration Hub subscription. For more information, see Legal schedules - Integration Hub overview. After the required plugin is activated, the step is visible under Integrations.
Available as an Workflow Studio action step. Users with the action_designer role can create a custom action with one or more action steps.
Inputs
Provide a value for each input that your action needs. To add dynamic values, you can also drag and drop pills from the Data panel or select them from the pill picker.
- Name
- Data type: String
Name part of a name-value pair. Enter a value or use a data pill to produce a dynamic payload.
- Value
- Data type: String
Value part of a name-value pair. Enter a value or use a data pill to produce a dynamic payload. You can use a complex object pill to populate a row with an object data type, but doing so deletes any children the complex object pill already has.
- Type
- Data type: ChoiceData type for the name-value pair. If you're using a data pill for the name or value, make sure the data type for the pill matches the data type selected here. The options are:
- String
- Object
- Number
- Boolean
- Array
For arrays and objects, use the plus icon (
) to add name-value pairs to the array or object.
- In case of empty value
- Data type: ChoiceOption to specify what to do if a name-value pair has an empty or null value.
- Leave as is: Keeps the empty or null value as an empty string.
- Omit property: Excludes a name-value pair if the value is empty or null.
- Set as null: Returns an empty or null value as a null data type.
- Throw error: Returns an error if a name-value pair has an empty or null value.
- Include Outer Structure
- Data type: True/False
Option to include the curly braces for a top-level JSON container.
- Omit Empty Structure
- Data type: True/False
Option to omit an empty payload. Empty payloads can occur when you select Omit property for the In case of empty value input for every name-value pair and all name-value pairs in the payload produce empty values.
- Structure
- Data type: Structure
Read-only payload the step produces.
- If this step fails
- Data type: Choice
Option to continue running the next step or go to error evaluation. To use the step status code or message for a custom action error condition, see Action error evaluation.
Outputs
These outputs appear in the Data panel. You can use them as inputs elsewhere in your action.
- Output
- Data type: String
JSON payload as a string. If you want to use the payload as an object, you can use the JSON parser step to parse the string.
- Step Status
- Data type: Object
Object data pill containing runtime details about the step. Each step in an action returns a Step Status.
- Step Status > Code
- Data type: Integer
Integer data pill indicating whether the step produced an error. By default, a value of 1 indicates that the step produced an error. A value of 0 indicates that the step ran successfully. You can't customize these codes.
- Step Status > Message
- Data type: String
String data pill containing the error message produced by the step or system operation. You can't customize this message.
Generate a JSON Payload
Automatically generate a JSON payload with the Add JSON for Payload button. This button opens the Add Payload script editor where you can enter a JSON payload to be automatically de-serialized into structured input.
- If the JSON has empty keys, the payload is still generated.
- If there are duplicate keys in the script editor, the last key entry in the object overrides the value of any previous keys with the same name.
- If the root object is an array, the root array is wrapped into a root object.
- If an array contains multiple objects, all the keys in the objects are coalesced into one parent object.
- empty payloads
- non-complex object types
- invalid JSON
- empty root objects, such as an empty array
- payloads larger than 65,000 bytes