Mapping an Array of Objects

Mapping an array of objects in the input to an array of identical objects in the output schema is a two step process. Map the array root first and then map each individual element within the object separately. Only the mapped elements will be included in the input.

To create a single item array, configure the array.forEach() function in the expression mapper for the array. You can then configure mappings for the items in that array. Any combination of the following can be used in an item mapping:
  • Literal or constant values, for example "My Value"
  • Functions, for example string.tostring(100)
  • Output of trigger/previous activities, for example $flow.body.Data.FirstName
To iterate over an array from the output of previous activities or trigger, configure array.forEach(<source array>) function in the expression mapper for the array. This will create an array of the same size as the source array. You can then configure mappings for the elements in that array. Any combination mentioned above can be used in an item mapping.
Caution: Once source array is configured and mapping of element(s) is completed, any change in source array would require you to manually update any mappings that are using element(s) from the source array.
Note: If you delete a parent mapping, you cannot edit or view its child mappings, even though the child mappings are not deleted from the system. But if you map the parent again, the previous child mapping will automatically appear and you will then be able to view and edit them.
In the example below [ ] Passenger is an array of objects. Each record (object) in Passenger has multiple properties that are of different data types, for example every customer has a property named “ID” which is of type number, a property named “Single” which of type boolean and so on. We map the Passenger input array to the output of the same array from the trigger in the flow.

To map these arrays, follow these steps:

Procedure

  1. Click [ ] Passenger in the input schema on the left.
    This opens the mapper to its right in the gray area.
  2. In the mapper, click [ ] Passenger in the output array to map it to the input array of the same name.
    Doing so inserts the array.forEach function (array.forEach($trigger.body.Passenger)) in the text box with the Passenger automatically inserted as the input to the forEach function. The forEach function loops through the Passenger array and maps each element in each record object with the corresponding element that you select in the output array.

    If the arrays are identical in the number of elements, their names and their type, and you want to map every single element in the array to the corresponding element in the identical array in the mapper, you need not do anything more. Mapping the root of the array will automatically map all its elements.

    If you want to map only particular elements of an array, you need to map each element within the customer object after you have mapped the array root.

  3. To map an element in the customer object, click it in the input array to open the mapper for that element. In our example, we will map the Name element, so click Name in the input array on the left.

  4. Click Name in the output array.
    The variable $.Name appears in the text box. This indicates that the Name element in the record object has been mapped. The forEach function uses this mapping for the Name element in each customer object within the [ ] Passenger input array.
  5. Continue mapping other elements that you want to map in the customer object in a similar manner.
    Note: To populate data in an activity that does not have any preceding activities, simply enter the data in the expression text box manually.