cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Change OBJECT to ARRAY using Mapper

hpv
Former Employee

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

In the below pipeline , data is generated using csv generator in plain text.
Pipeline
4a342a59edb2c1aa8c8347ccad6bf269f57eeffb.JPG
CSV generator configurations
21aeeb2b8b82dbe20871c90914897d8f1fc364f2.JPG

Changing the name from object to list.

0f683bde20fb3b3778fa011f8de1293945c5f0af.JPG

$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" } ]

e4336fa1d4f860d077fb164681441488b7488281.JPG

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

1572dbe5679181c5232bdd1959947f233dce004c.JPG

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 1

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.