The Search/JSONPropertySearch extension parses a JSON string that contains a nested array and searches for the first nested value that includes the provided search text.
This is useful when a journey needs to look up a paired value from a nested JSON array, such as finding a configured label, code, or mapped value from runtime data and returning the related value for later validation.
Parameters:
-
jsonrequired, a JSON string representing the nested array structure to search. The string must parse successfully withJSON.parse; -
searchStringrequired, a string searched using JavaScriptincludesagainstitem[0][0]in each nested array item;
Note: The extension expects a very specific nested array shape where each item contains item[0][0] for the searchable value and item[0][1] for the returned value.
NLP usage
Use the extension in a journey by calling Search/JSONPropertySearch with the execute command. Pass each value to the matching extension input using as inputName.
Note: This extension runs synchronously. It returns the first matching value only. If no match is found, it returns No match found. If JSON parsing fails, the code logs the error but does not explicitly return a failure message.
execute "Search/JSONPropertySearch" using '[[[["State", "ALBERTA"]]], [[["Code", "AB"]]]]' as json and "State" as searchString returning $responseexecute "Search/JSONPropertySearch" using '[[[["Product", "Laptop"]]], [[["Region", "APAC"]]]]' as json and "Region" as searchString returning $responseYou can also pass JSON and search text from variables when the nested array is created or captured earlier in the journey.
execute "Search/JSONPropertySearch" using "$nestedJson" as json and "$lookupText" as searchString returning $responsestore value '[[[["Status", "Approved"]]], [[["Owner", "QA"]]]]' in $nestedJson
store value "Status" in $lookupText
execute "Search/JSONPropertySearch" using "$nestedJson" as json and "$lookupText" as searchString returning $responseExample output when the first searchable value contains the requested text:
ApprovedThis extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension is designed for a specific nested array structure and does not perform defensive checks for every nested level before accessing item[0][0] and item[0][0][1]. It uses case-sensitive includes, returns only the first match, does not support deep object property searching, and may return only the second character from the matched string if the input shape is not exactly aligned with the code's indexing.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 25/05/2026
Resources:
This extension does not require any external resource.
function findMatchingValue(array, searchString) {
const filteredArray = array.filter(item => item.length > 0 && item[0][0].includes(searchString));
if (filteredArray.length > 0) {
return filteredArray[0][0][1];
} else {
return "No match found";
}
}
try {
const nestedArray = JSON.parse(json);
const result = findMatchingValue(nestedArray, searchString);
console.log(result);
return result;
} catch (error) {
console.error("An error occurred:", error);
}
Comments
0 comments
Please sign in to leave a comment.