Loading
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Transforming Lists with Data Mappers

          Transforming Lists with Data Mappers

          Data Mappers can perform list transformations. For mapping input to output, Data Mappers require a list input in which every value is paired with a key.

          For example, the following lists are valid, and each can be converted to the other.

          List 1:

          {
           "Oldest": "Huey",
           "Middle": "Dewey",
           "Youngest": "Louie"
          }
          

          List 2:

          {
              "Nephews": [
                  {
                      "Name": "Huey"
                  },
                  {
                      "Name": "Dewey"
                  },
                  {
                      "Name": "Louie"
                  }
              ]
          }

          List 1 lacks a JSON node for the list as a whole, and each value has a different key. List 2 has its own JSON node, and each list item has the same key.

          Note
          Note Loop Block components in Integration Procedures require input that is structured like List 2. The list-item key itself can contain key-value pairs. For examples, see Work with Data and Lists.

          To convert List 1 to List 2, use the following mappings on the Transforms tab of a Data Mapper Transform. The |1, |2, and |3 are list position indexes.

          Input JSON Path

          Output JSON Path

          Oldest

          Nephews|1:Name

          Middle

          Nephews|2:Name

          Youngest

          Nephews|3:Name

          To convert List 2 to List 1, use the reverse mappings.

          In the following list, values don't have keys.

          List 3:

          {
            "Nephews": [
              "Huey",
              "Dewey",
              "Louie"
            ]
          }
          

          You can convert List 1 to List 3 using the following mappings:

          Input JSON Path

          Output JSON Path

          Oldest

          Nephews|1

          Middle

          Nephews|2

          Youngest

          Nephews|3

          However, you can't convert List 3 to either List 1 or List 2.

          To convert List 2 to List 3, and to perform such conversions of lists of any length, see Convert a List of Objects to a List of Values.

          If each object of a list has a different key, Data Mapper Transform creates a single map with combined key and value pairs from that list, and ignores any empty values. Here’s an example for products for an ecommerce website:

          {
              "Cleaning products": [
                  {
                      "Name": "WonderProduct"
                      "Property": ""
                  },
                  {
                      "Name": ""
                      "Property": "Fast-acting"
                  },
                  {
                      "Scent": "Lavender"
                  }
              ]
          }
          

          Transformed output list:

          {
              "Cleaning products": [
                  {
                      "Name": "WonderProduct"
                      "Property": "Fast-acting"
                      "Scent": ":Lavender"
                  }
              ]
          }
          

          For more that you can do with lists, see:

          Expected Behavior for Array Inputs

          When a list input (array) is mapped to an output that is expected to be a single object (non-array), the Data Mapper Transform automatically flattens the array or merges the objects based on the number of records in the input array.

          • If the list input array has two records, the Data Mapper Transform flattens the array and attempts to merge the records into a single JSON object in the output. The output node is a single object {} instead of an array [].

            Example input:

            {
            "In": [
              { "field1": "data1" },
              { "field2": "data2" }
             ]
            }

            Example output:

            {
             "Out": {
              "field1": "data1",
              "field2": "data2"
             }
            }
          • If the input array contains more than two records (multiple objects), the Data Mapper Transform retains the array structure and does not flatten the records. The array is returned in the output as-is.

            Example input:

            {
             "In": [
              { "field1": "data1" },
              { "field2": "data2" },
              { "field3": "data3" }
             ]
            }

            Example output:

            {
             "Out": [
              { "field1": "data1" },
              { "field2": "data2" },
              { "field3": "data3" }
             ]
            }
           
          Loading
          Salesforce Help | Article