The Search/arrayStringLength extension checks each item in a JSON array and confirms that every item is a string, is not null or undefined, is not blank after trimming, and stays within the configured minimum and maximum string length.
This is useful when a journey needs to validate search results, table values, API-derived arrays, or extracted text collections before continuing with later checks that depend on clean string data.
Parameters:
-
Arrayrequired, a JSON string representing the array of values to validate. The source code parses this input withJSON.parse(Array), so pass a valid JSON array string such as["hello","world"]; -
MinLengthrequired, the minimum allowed string length. This value is compared with each item'slength; -
MaxLengthrequired, the maximum allowed string length. This value is compared with each item'slength;
Note: The Array input must be valid JSON. Use double quotes inside the array values, for example ["hello","world"]. The script treats whitespace-only strings as empty because it checks item.trim() === '' before checking length.
How to apply this to your journey
Use the extension in a journey by calling Search/arrayStringLength with the execute command. Pass each value to the matching extension input using as Array, as MinLength, and as MaxLength.
Note: Because this extension returns a plain text success or error message, store the result in a variable and assert against the returned message text in later journey steps when needed.
execute "Search/arrayStringLength" using '["hello","world","sample"]' as Array, "2" as MinLength and "10" as MaxLength returning $responseexecute "Search/arrayStringLength" using '["hello","world",null,"!","this is a test",""]' as Array, "2" as MinLength and "10" as MaxLength returning $responseYou can also pass journey variables into the extension when the array or length values are prepared earlier in the journey.
execute "Search/arrayStringLength" using "$arrayValues" as Array, "$minLength" as MinLength and "$maxLength" as MaxLength returning $responsestore value '["hello","world","sample"]' in $arrayValues
store value "2" in $minLength
store value "10" in $maxLength
execute "Search/arrayStringLength" using "$arrayValues" as Array, "$minLength" as MinLength and "$maxLength" as MaxLength returning $responseExample successful output:
All items meet the length requirements and are not null.Example validation error output:
Errors found:
Item at index 2 is null or undefined.
Item at index 3 is shorter than the minimum length of 2.
Item at index 4 is longer than the maximum length of 10.
Item at index 5 is an empty string.This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension performs synchronous JavaScript validation only and does not use browser-specific APIs beyond standard JavaScript array, string, and JSON parsing behavior. The Array input must be a valid JSON array; malformed JSON, a non-array value, or a missing input will cause the step to fail before validation messages can be returned. The code assumes the parsed value supports forEach, so objects, numbers, or plain comma-separated strings are not supported. Length is checked with JavaScript string length, which counts UTF-16 code units rather than user-visible characters, so emoji, combined characters, and some multilingual text may not match a human-perceived character count. The checks are case-sensitive and do not normalize whitespace except for detecting empty trimmed strings. Cross-browser note: This extension does not intentionally use browser-specific APIs beyond standard JavaScript. Still, validate it in the browser/device configurations used by your plans when it is combined with page state, network calls, external libraries, or DOM-dependent journey steps.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 04/06/2026
Resources:
This extension does not require any external resource.
function assertLengthAndNoNulls(array, minLength, maxLength) {
const errors = [];
array.forEach((item, index) => {
if (item === null || item === undefined) {
errors.push(`Item at index ${index} is null or undefined.`);
} else if (typeof item !== 'string') {
errors.push(`Item at index ${index} is not a string.`);
} else if (item.trim() === '') {
errors.push(`Item at index ${index} is an empty string.`);
} else if (item.length < minLength) {
errors.push(`Item at index ${index} is shorter than the minimum length of ${minLength}.`);
} else if (item.length > maxLength) {
errors.push(`Item at index ${index} is longer than the maximum length of ${maxLength}.`);
}
});
if (errors.length > 0) {
return { success: false, errors: errors };
} else {
return { success: true, message: 'All items meet the length requirements and are not null.' };
}
}
// Example usage:
const array = JSON.parse(Array);
const minLength = MinLength;
const maxLength = MaxLength;
const result = assertLengthAndNoNulls(array, minLength, maxLength);
if (result.success) {
console.log(result.message);
return result.message;
} else {
console.error('Errors found:');
result.errors.forEach(error => console.error(error));
return `Errors found:
${result.errors.join('
')}`;
}
Comments
0 comments
Please sign in to leave a comment.