Forum Discussion

hpv's avatar
hpv
Former Employee
9 years ago

Change OBJECT to ARRAY using Mapper

Using Mapper, we can change the Object in to array.

In the below pipeline , data is generated using csv generator in plain text.
Pipeline

CSV generator configurations

Changing the name from object to list.

$Name instanceof Array?$Name :[$Name]

Here name is the attribute which is reffered from csv generator and is converted to list from object.

Output of Mapper
[ { "Name": [ "Harish" ], "age": "26" } ]

Here added an JSON splitter to read the list from the output of mapper.

Below is the output of JSON splitter.
[ { "splitValue": "Harish" } ]

Attaching the sample pipeline.Array to Object_2017_03_06.slp (4.0 KB)

1 Reply

  • darkomak24's avatar
    darkomak24
    New Contributor II

    You can also use the sl.ensureArray($Name) expression. Using this expression you will make sure that the $Name object will be array.