You are here:
Concatenate List Items
This Integration Procedure example concatenates values from an array into a single comma-separated string by using a Set Values Action inside a Loop Block, then trimming and returning the output.
For this example, use this simple JSON input:
{
"Items": [
{
"Item": "First"
},
{
"Item": "Second"
},
{
"Item": "Third"
}
]
}
You create a Loop Block, with Items as the Loop List.
Inside the Loop Block, you use a Set Values Action to add the value of each
Item to a string called ConcatString. Finally, you trim
the extra characters from ConcatString by using a Set Values action, then
use a Response Action to pass ConcatString to the output.
Use the following steps to configure the Integration Procedure.
-
Create a Loop Block with
Itemsin the Loop List field. -
Inside the Loop Block, create a Set Values Action to concatenate the current item to
ConcatString. -
In the Set Values Action's Element Value Map, add one element,
Concat, that gets the current value ofConcatStringand adds Item.- Element Name:
Concat - Value:
=%ConcatString% + ", " + %Items:Item%
- Element Name:
-
Use the Response JSON to put Concat into ConcatString for the next round.
- Response JSON Path:
Concat - Response JSON Node:
ConcatString
- Response JSON Path:
-
After the Loop Block, the strings are concatenated, but there’s an extra comma and
space at the beginning of
ConcatStringfrom the first execution of the loop. You can trim the output by adding a Set Values component after the Loop Block.- Element Name:
TrimOutput - Element Value Map:
ConcatString- Element Name:
TrimmedString - Value:
=SUBSTRING(ConcatString, 2)
- Element Name:
- Element Name:
-
Finally, send the resulting TrimmedString from TrimOutput to the output by using a Response Action.
- Send JSON Path:
TrimOutput:TrimmedString - Send JSON Node:
Output
- Send JSON Path:
The output looks like this.
{
"Output": "First, Second, Third"
}
