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.

  1. Create a Loop Block with Items in the Loop List field.
  2. Inside the Loop Block, create a Set Values Action to concatenate the current item to ConcatString.
  3. In the Set Values Action's Element Value Map, add one element, Concat, that gets the current value of ConcatString and adds Item.
    • Element Name: Concat
    • Value: =%ConcatString% + ", " + %Items:Item%
  4. Use the Response JSON to put Concat into ConcatString for the next round.
    • Response JSON Path: Concat
    • Response JSON Node: ConcatString
  5. After the Loop Block, the strings are concatenated, but there’s an extra comma and space at the beginning of ConcatString from 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)
  6. Finally, send the resulting TrimmedString from TrimOutput to the output by using a Response Action.
    • Send JSON Path: TrimOutput:TrimmedString
    • Send JSON Node: Output

The output looks like this.

{
 "Output": "First, Second, Third"
}