Send feedback
Stay organized with collections
Save and categorize content based on your preferences.
See the supported connectors for Application Integration.
FOR_EACH function
FOR_EACH
function
Function Name
Description
Usage
Input parameter
Return value
FOR_EACH
Applies one or more transformation functions for each element in an array.
FOR_EACH(~objn -> Variable or Value)
Where ~objn indicates the current array iteration element for which you want to apply the transformation functions. By default, the value for n starts from 1.
For JSON arrays with schema, you can use a dot (.) notation following to the current array element to directly access the nested property of the that array element. See example .
Transformation functions.
An array of elements.
Supported data type
The FOR_EACH
function supports the following data types:
Boolean array
Double array
Integer array
JSON
String array
Example 1: Concat a value to all the elements of a string array.
Sample data : $var1$ = {"Alex","Bola","Charlie","Dana","Hao"}
Usage : $var1$.FOR_EACH(~obj1-> ~obj1.CONCAT("@gmail.com"))
Concat the value @gmail.com to var1 .
Output :
{
"Alex@gmail.com",
"Bola@gmail.com",
"Charlie@gmail.com",
"Dana@gmail.com",
"Hao@gmail.com"
}
Example 2: Given a JSON array without schema, add a property to all the JSON objects.
Sample data :
$var1$ =
{
"employeeDetails": [
{
"name": "Alex"
},
{
"name": "Bola"
},
{
"name": "Charlie"
}
]
}
Usage : $var1$.employeeDetails.FOR_EACH(~obj1-> ~obj1.SET_PROPERTY("Google","company"))
Add the property company:Google to var1 .
Output :
[
{
"name": "Alex",
"company": "Google"
},
{
"name": "Bola",
"company": "Google"
},
{
"name": "Charlie",
"company": "Google"
}
]
Example 3: Given a JSON array without schema, add a property to all the nested JSON objects.
Sample data :
$var1$ =
{
"employeeDetails": [
{
"name": "Alex",
"details": [
{
"age": "27",
"address": "1800 Amphibious Blvd. Mountain View, CA 94045"
}
]
},
{
"name": "Bob",
"details": [
{
"age": "25",
"address": "8 Rue du Nom Fictif 341 Paris"
}
]
}
],
"deptDetails": [
{
"id1": "HR"
},
{
"id2": "Finance"
},
{
"id3": "Sales"
}
]
}
Usage : $var1$.employeeDetails.FOR_EACH(~obj1-> ~obj1.GET_PROPERTY("details").FOR_EACH(~obj2-> ~obj2.SET_PROPERTY("dd/mm/yyyy", "dob")))
Add the placeholder property dob: "dd/mm/yyyy" to details in var1 .
Output :
[
[
{
"age": "27",
"address": "1800 Amphibious Blvd. Mountain View, CA 94045",
"dob": "dd/mm/yyyy"
}
],
[
{
"age": "25",
"address": "8 Rue du Nom Fictif 341 Paris",
"dob": "dd/mm/yyyy"
}
]
]
Example 4: Given a JSON array with schema, concat the nested properties of the JSON object.
Sample data :
$var1$ =
{"citynames": [
{
"city": "Abbeville",
"info": {
"pincode": 29620,
"state": "South Carolina",
"location" : {
"lat" : "50.1055 N",
"lon": "1.8368 E"
}
}
},
{
"city": "Aberdeen",
"info": {
"pincode": AB10,
"state": "Scotland",
"location" : {
"lat" : "57.1499 N",
"lon": "2.0938 W"
}
}
},
{
"city": "Benicia",
"info": {
"pincode": 94510,
"state": "California",
"location" : {
"lat" : "38.0494 N",
"lon": "122.1586 W"
}
}
}
]
}
Usage : $var1$.citynames.FOR_EACH(~obj1-> ~obj1.city.CONCAT(",").CONCAT(~obj1.info.location.lat).CONCAT(",").CONCAT(~obj1.info.location.lon))
Concat the nested properties of city using a separator (,) in var1 .
Output :
[
"Abbeville,50.1055 N,1.8368 E",
"Aberdeen,57.1499 N,2.0938 W",
"Benicia,38.0494 N,122.1586 W"
]
Example 5: Resolve a JSON array object reference in a template JSON.
Sample data :
$var2$ =
{
"cityName": "$~obj1.city$",
"latitude": "$~obj1.info.location.lat$",
"longitude": "$~obj1.info.location.lon$"
}
$var1$ =
{"citynames": [
{
"city": "Abbeville",
"info": {
"pincode": 29620,
"state": "South Carolina",
"location" : {
"lat" : "50.1055 N",
"lon": "1.8368 E"
}
}
},
{
"city": "Aberdeen",
"info": {
"pincode": AB10,
"state": "Scotland",
"location" : {
"lat" : "57.1499 N",
"lon": "2.0938 W"
}
}
},
{
"city": "Benicia",
"info": {
"pincode": 94510,
"state": "California",
"location" : {
"lat" : "38.0494 N",
"lon": "122.1586 W"
}
}
}
]
}
Usage : $var1$.citynames.FOR_EACH(~obj1-> $var2$.RESOLVETEMPLATE())
Resolves references of ~obj1
in var2 , where ~obj1
is the current iterating element of var1 .
Output :
[
{
"cityName": "Abbeville",
"latitude": "50.1055 N",
"longitude": "1.8368 E",
}
{
"cityName": "Aberdeen",
"latitude": "57.1499 N",
"longitude": "2.0938 W",
}
{
"cityName": "Benicia",
"latitude": "38.0494 N",
"longitude": "122.1586 W",
}
]
Recommendation
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-29 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eFOR_EACH\u003c/code\u003e function applies one or more transformation functions to each element within an array, enabling operations on multiple array elements at once.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eFOR_EACH\u003c/code\u003e supports various data types including boolean, double, integer, JSON, and string arrays, providing versatility in data manipulation.\u003c/p\u003e\n"],["\u003cp\u003eThe function allows users to concatenate values, add properties to JSON objects, and manipulate nested JSON structures as demonstrated in the provided examples.\u003c/p\u003e\n"],["\u003cp\u003eThe function also supports resolving JSON array object references in a template JSON, allowing dynamic data insertion into predefined templates.\u003c/p\u003e\n"],["\u003cp\u003eWith usage of the \u003ccode\u003eFOR_EACH\u003c/code\u003e function, the current array iteration element can be used to access nested properties of JSON array elements through the use of dot notation.\u003c/p\u003e\n"]]],[],null,["# FOR_EACH function\n\nSee the [supported connectors](/integration-connectors/docs/connector-reference-overview) for Application Integration.\n\nFOR_EACH function\n=================\n\n`FOR_EACH` function\n-------------------\n\nSupported data type\n-------------------\n\n\nThe `FOR_EACH` function supports the following data types:\n\n- Boolean array\n- Double array\n- Integer array\n- JSON\n- String array\n\nExample 1: Concat a value to all the elements of a string array.\n----------------------------------------------------------------\n\n\n**Sample data** : `$var1$ = {\"Alex\",\"Bola\",\"Charlie\",\"Dana\",\"Hao\"}`\n\n\n**Usage** : `$var1$.FOR_EACH(~obj1-\u003e ~obj1.CONCAT(\"@gmail.com\"))`\n\n\nConcat the value *@gmail.com* to *var1*.\n\n\n**Output** :\n`\n{\n\"Alex@gmail.com\",\n\"Bola@gmail.com\",\n\"Charlie@gmail.com\",\n\"Dana@gmail.com\",\n\"Hao@gmail.com\"\n}\n`\n\nExample 2: Given a JSON array without schema, add a property to all the JSON objects.\n-------------------------------------------------------------------------------------\n\n\n**Sample data**: \n\n```\n $var1$ =\n{\n \"employeeDetails\": [\n {\n \"name\": \"Alex\"\n },\n {\n \"name\": \"Bola\"\n },\n {\n \"name\": \"Charlie\"\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\n\n**Usage** : `$var1$.employeeDetails.FOR_EACH(~obj1-\u003e ~obj1.SET_PROPERTY(\"Google\",\"company\"))`\n\n\nAdd the property *company:Google* to *var1*.\n\n\n**Output**: \n\n```\n[\n {\n \"name\": \"Alex\",\n \"company\": \"Google\"\n },\n {\n \"name\": \"Bola\",\n \"company\": \"Google\"\n },\n {\n \"name\": \"Charlie\",\n \"company\": \"Google\"\n }\n]\n```\n\n\u003cbr /\u003e\n\nExample 3: Given a JSON array without schema, add a property to all the nested JSON objects.\n--------------------------------------------------------------------------------------------\n\n\n**Sample data**: \n\n```\n $var1$ =\n{\n \"employeeDetails\": [\n {\n \"name\": \"Alex\",\n \"details\": [\n {\n \"age\": \"27\",\n \"address\": \"1800 Amphibious Blvd. Mountain View, CA 94045\"\n }\n ]\n },\n {\n \"name\": \"Bob\",\n \"details\": [\n {\n \"age\": \"25\",\n \"address\": \"8 Rue du Nom Fictif 341 Paris\"\n }\n ]\n }\n ],\n \"deptDetails\": [\n {\n \"id1\": \"HR\"\n },\n {\n \"id2\": \"Finance\"\n },\n {\n \"id3\": \"Sales\"\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\n\n**Usage** : `$var1$.employeeDetails.FOR_EACH(~obj1-\u003e ~obj1.GET_PROPERTY(\"details\").FOR_EACH(~obj2-\u003e ~obj2.SET_PROPERTY(\"dd/mm/yyyy\", \"dob\")))`\n\n\nAdd the placeholder property *dob: \"dd/mm/yyyy\"* to *details* in *var1*.\n\n\n**Output**: \n\n```\n [\n [\n {\n \"age\": \"27\",\n \"address\": \"1800 Amphibious Blvd. Mountain View, CA 94045\",\n \"dob\": \"dd/mm/yyyy\"\n }\n ],\n [\n {\n \"age\": \"25\",\n \"address\": \"8 Rue du Nom Fictif 341 Paris\",\n \"dob\": \"dd/mm/yyyy\"\n }\n ]\n ]\n```\n\n\u003cbr /\u003e\n\nExample 4: Given a JSON array with schema, concat the nested properties of the JSON object.\n-------------------------------------------------------------------------------------------\n\n\n**Sample data**: \n\n```\n $var1$ =\n {\"citynames\": [\n {\n \"city\": \"Abbeville\",\n \"info\": {\n \"pincode\": 29620,\n \"state\": \"South Carolina\",\n \"location\" : {\n \"lat\" : \"50.1055 N\",\n \"lon\": \"1.8368 E\" \n } \n } \n },\n {\n \"city\": \"Aberdeen\",\n \"info\": {\n \"pincode\": AB10,\n \"state\": \"Scotland\",\n \"location\" : {\n \"lat\" : \"57.1499 N\",\n \"lon\": \"2.0938 W\" \n } \n } \n },\n {\n \"city\": \"Benicia\",\n \"info\": {\n \"pincode\": 94510,\n \"state\": \"California\",\n \"location\" : {\n \"lat\" : \"38.0494 N\",\n \"lon\": \"122.1586 W\" \n } \n } \n }\n ]\n }\n```\n\n\u003cbr /\u003e\n\n\n**Usage** : `$var1$.citynames.FOR_EACH(~obj1-\u003e ~obj1.city.CONCAT(\",\").CONCAT(~obj1.info.location.lat).CONCAT(\",\").CONCAT(~obj1.info.location.lon))`\n\n\nConcat the nested properties of *city* using a separator (,) in *var1*.\n\n\n**Output**: \n\n```\n[\n \"Abbeville,50.1055 N,1.8368 E\",\n \"Aberdeen,57.1499 N,2.0938 W\",\n \"Benicia,38.0494 N,122.1586 W\"\n]\n```\n\n\u003cbr /\u003e\n\nExample 5: Resolve a JSON array object reference in a template JSON.\n--------------------------------------------------------------------\n\n\n**Sample data**: \n\n```\n $var2$ =\n {\n \"cityName\": \"$~obj1.city$\",\n \"latitude\": \"$~obj1.info.location.lat$\",\n \"longitude\": \"$~obj1.info.location.lon$\"\n }\n \n``` \n\n```\n $var1$ =\n {\"citynames\": [\n {\n \"city\": \"Abbeville\",\n \"info\": {\n \"pincode\": 29620,\n \"state\": \"South Carolina\",\n \"location\" : {\n \"lat\" : \"50.1055 N\",\n \"lon\": \"1.8368 E\" \n } \n } \n },\n {\n \"city\": \"Aberdeen\",\n \"info\": {\n \"pincode\": AB10,\n \"state\": \"Scotland\",\n \"location\" : {\n \"lat\" : \"57.1499 N\",\n \"lon\": \"2.0938 W\" \n } \n } \n },\n {\n \"city\": \"Benicia\",\n \"info\": {\n \"pincode\": 94510,\n \"state\": \"California\",\n \"location\" : {\n \"lat\" : \"38.0494 N\",\n \"lon\": \"122.1586 W\" \n } \n } \n }\n ]\n }\n \n```\n\n\u003cbr /\u003e\n\n\n**Usage** : `$var1$.citynames.FOR_EACH(~obj1-\u003e $var2$.RESOLVETEMPLATE())`\n\n\nResolves references of `~obj1` in *var2* , where `~obj1` is the current iterating element of *var1*.\n\n\n**Output**: \n\n```\n[\n {\n \"cityName\": \"Abbeville\",\n \"latitude\": \"50.1055 N\",\n \"longitude\": \"1.8368 E\",\n }\n {\n \"cityName\": \"Aberdeen\",\n \"latitude\": \"57.1499 N\",\n \"longitude\": \"2.0938 W\",\n }\n {\n \"cityName\": \"Benicia\",\n \"latitude\": \"38.0494 N\",\n \"longitude\": \"122.1586 W\",\n }\n \n]\n```\n\n\u003cbr /\u003e\n\nRecommendation\n--------------\n\n- Learn how to add and configure a [Data Mapping task](/application-integration/docs/configure-data-mapping-task)"]]