Articles in this section

Mapper 2.0: Convert primitive arrays to object arrays

Mapper 2.0 makes it easy for you to convert raw, primitive data into structured records, without scripting but using UI options. When converting, you can map each element into a single key (user-defined, or using a constant key "value"`). Also, you can use the existing indexing support with this capability, making it easier to reference array elements and complete downstream transformations for data Ingestion use cases where unique keys aren’t available.

Supported primitive arrays for conversion

You can convert the following array types to object arrays:

  • string array
  • number array
  • boolean arrays

In Mapper 2.0, try the following procedure with a simple conversion sample. Then you can test more complex scenarios.

  1. For source fields: Select the source field values from the list.

    mapper2_0-source-field.png
  2. Click Settings (gear.svg). to view that the source data type is set to string, number, or boolean array based on your scenario. (The default setting for Copy an array from the source as-is is Yes. See the examples below for Yes or No options. ).

    mapper2_0-source-datatype.png
  3. For destination fields: Enter a Destination field.
  4. Set the destination data type to Convert to object array.

    mapper-2_0-destination-dataype.png
  5. Click Preview and check your output. Click Save.

Example – 1

In your source mapping, the default option for Copy an array from the source as-is for number, string, boolean arrays is set to Yes.

mapper-2_0-copy-source-as-is-yes.png

If you have a simple string array for say, colors of your product like this as the input.

{ "colors": [ "pink", "red", "green" ]
}

Then, the string array is automatically converted to an object array and the default key used is "value" as shown in the output below.

mapper-2_0-primitive-1.png

Example – 2

In your source mapping, you can change the option for Copy an array from the source as-is to No, if you want to use a custom value for the key or to reference array elements using indexing.

mapper-2_0-copy-source-as-is-no.png

You must set a custom value for the key using $ to convert the string array to an object array. In this example, the custom value is "Color". You can also reference array elements using currentIndex().

primitive-array-conversion-example-2.png