The Compare/arrayComparisonChecker extension compares two arrays from inside a Virtuoso journey and reports mismatched or extra values.
This is useful when your test needs to compare data captured from the application with expected values from test data and identify where the arrays differ.
Parameters:
-
applicationDatarequired, a JSON string representing the array of values captured from the application; -
dataTablerequired, a JSON string representing the expected array of test data values.
Note: Both inputs must be valid JSON arrays. If either input is not an array, the extension throws Both inputs must be arrays..
NLP usage
Use the extension in a journey by calling Compare/arrayComparisonChecker with the execute command. Pass each value to the matching extension input using as inputName.
Note: The extension compares values by array index and also checks whether unmatched values are extra in either array.
To compare two arrays directly:
execute "Compare/arrayComparisonChecker" using '["Apple","Banana","Orange"]' as applicationData, '["Apple","Grape","Orange"]' as dataTable returning $comparisonResultTo compare arrays with extra values:
execute "Compare/arrayComparisonChecker" using '["A","B","C"]' as applicationData, '["A","B"]' as dataTable returning $comparisonResultYou can also use Virtuoso variables to make the same step reusable across different application values and expected test data:
execute "Compare/arrayComparisonChecker" using "$applicationData" as applicationData, "$expectedData" as dataTable returning $comparisonResultExample setup using variables before calling the extension:
store value '["Apple","Banana","Orange"]' in $applicationData
store value '["Apple","Grape","Orange"]' in $expectedData
execute "Compare/arrayComparisonChecker" using "$applicationData" as applicationData, "$expectedData" as dataTable returning $comparisonResultExample response when mismatches are found:
{"mismatched": "\n\"Banana\" in appData and \"Grape\" in testData\n", "extraElements": "\n\"Banana\" in appData at index 1,\n\"Grape\" in testData at index 1\n"}Example response when no mismatches are found:
{"mismatched": "", "extraElements": "", "output": "No mismatch or extra elements found"}This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension performs a simple index-based comparison and uses includes to detect extra values. It is best suited for primitive array values such as strings or numbers. It does not perform deep object comparison, case-insensitive comparison, sorting, or duplicate-aware matching.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 22/05/2026
Resources: None
const appData = JSON.parse(applicationData);
const testData = JSON.parse(dataTable);
if (!Array.isArray(appData) || !Array.isArray(testData)) {
throw new Error('Both inputs must be arrays.');
}
const mismatches = [];
const extraElements = [];
for (let i = 0; i < appData.length || i < testData.length; i++) {
if (appData[i] !== testData[i]) {
if (appData[i] !== undefined && !testData.includes(appData[i])) {
extraElements.push({ index: i, value: appData[i], source: 'appData' });
}
if (testData[i] !== undefined && !appData.includes(testData[i])) {
extraElements.push({ index: i, value: testData[i], source: 'testData' });
}
mismatches.push(i);
} else if (appData[i] === undefined && testData[i] !== undefined) {
extraElements.push({ index: i, value: testData[i], source: 'testData' });
} else if (testData[i] === undefined && appData[i] !== undefined) {
extraElements.push({ index: i, value: appData[i], source: 'appData' });
}
}
if (mismatches.length > 0 || extraElements.length > 0) {
const mismatchedArr = mismatches.map(i => [appData[i], testData[i]]);
const mismatchedValuesStr = mismatchedArr.map(([value1, value2]) => {
return `"${value1}" in appData and "${value2}" in testData`;
}).join(',\n');
const extraElementsStr = extraElements.map(({ index, value, source }) => {
return `"${value}" in ${source} at index ${index}`;
}).join(',\n');
const mismatchedOutput = mismatches.length > 0
? `\n${mismatchedValuesStr}\n`
: '';
const extraElementsOutput = extraElements.length > 0
? `\n${extraElementsStr}\n`
: '';
const output = {
mismatched: mismatchedOutput,
extraElements: extraElementsOutput
};
return output;
} else {
return { mismatched: '', extraElements: '', output: 'No mismatch or extra elements found' };
}
Comments
0 comments
Please sign in to leave a comment.