Script Tab in Node Settings
The Script tab is designed for placing JavaScript code that handles the node's programmatic logic. Here you define what exactly your node does - whether it processes text, calls APIs, transforms data, or performs calculations.

Code Structure
All Piper nodes, including custom ones, follow a specific JavaScript structure:
export async function run({ inputs }) {
const { FatalError, NextNode } = DEFINITIONS;
// Your code here
return NextNode.from({
outputs: {
// Your results
}
});
}
This structure ensures that your node can properly receive data from previous nodes and pass results to the next ones in your pipeline.
Original Input Text Code
The basic Input Text node has this simple structure:
export async function run({ inputs }) {
const { FatalError, NextNode } = DEFINITIONS;
const text = inputs.input_text;
return NextNode.from({
outputs: {
output_text: text
}
});
}
Custom Merge Text to JSON Code
We need to replace this with logic that processes multiple string inputs and creates a JSON array:
export async function run({ inputs }) {
const { FatalError, NextNode } = DEFINITIONS;
const jsonArray = [];
if (inputs.string1) {
jsonArray.push(inputs.string1);
}
if (inputs.string2) {
jsonArray.push(inputs.string2);
}
if (inputs.string3) {
jsonArray.push(inputs.string3);
}
if (inputs.string4) {
jsonArray.push(inputs.string4);
}
return NextNode.from({
outputs: {
json_output: jsonArray
}
});
}
Understanding Custom Logic
The custom script implements the following logic:
- Initialize empty array -
const jsonArray = []creates an empty array to store our text strings - Check each input -
ifconditions check that each input has a value before adding - Build array - Only non-empty inputs are added to
jsonArrayusingpush() - Return JSON output - The final array is returned as
json_output, matching our configuration in the Design tab
This approach ensures that:
- Empty or undefined inputs are ignored
- Only valid text strings are included in the final JSON array
- The output format matches the JSON type we defined in the Design tab
Execution Types
Choose the appropriate execution type based on how much time your node requires to work:
| Type | Time | Description |
|---|---|---|
| Rapid | 0-20 sec | Fast operations |
| Regular | 21-60 sec | Standard processing |
| Deferred | 60-120 sec | Complex operations |
| Protracted | 120-300 sec | Heavy processing tasks |
For our Merge text to JSON node, Rapid execution is suitable since we're only manipulating text strings and there are no API calls to external services.
Saving Changes
Always save changes to the script by clicking the Save button at the bottom of the interface. Any changes to the code should be saved by pressing the Save button at the bottom of the interface.
The Script tab is the core of your node's functionality, where you transform input data into output using JavaScript code.