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.
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.
-
For source fields: Select the source field values from the list.
-
Click Settings (
). 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. ).
- For destination fields: Enter a Destination field.
-
Set the destination data type to Convert to object array.
- Click Preview and check your output. Click Save.
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.
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.
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.
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().