cancel
Showing results for 
Search instead for 
Did you mean: 

Convert comma separated values into different rows

skodali
New Contributor III

I’m trying to convert the comma separated values in a single row to a different number of rows.

Ques

Can anyone suggest me how should I approach?

1 ACCEPTED SOLUTION

tstack
Former Employee

I wanted to provide a solution that used the expression language in case others are interested.

Strings have a split() method that will split the string and return an array. From there, you can use the map() method to create key/value pairs, like so:

$Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem])

(The argument to map() is a callback function that will be called with each element in the array and its index. The function then creates an array with the first element being the property name “RoleN” and the second being the element itself.)

Once you have key/value pairs, you can feed it into the extend() method on objects to produce an object with the given pairs:

$.extend($Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem]))

Here’s an example pipeline:

SplitRoles_2019_01_24.slp (6.7 KB)

View solution in original post

7 REPLIES 7

Ajay_Chawda
Contributor

Hi Sasank,
May be below response can help you in what your are trying to achieve,
image

tempCsv_2019_01_24.slp (13.0 KB)

Usually JSON splitter snap will be used to perform this activity, so that in preceding snaps you can combine together and generate XLS data as output.

skodali
New Contributor III

Thanks Ajay it solves the issue.

tstack
Former Employee

I wanted to provide a solution that used the expression language in case others are interested.

Strings have a split() method that will split the string and return an array. From there, you can use the map() method to create key/value pairs, like so:

$Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem])

(The argument to map() is a callback function that will be called with each element in the array and its index. The function then creates an array with the first element being the property name “RoleN” and the second being the element itself.)

Once you have key/value pairs, you can feed it into the extend() method on objects to produce an object with the given pairs:

$.extend($Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem]))

Here’s an example pipeline:

SplitRoles_2019_01_24.slp (6.7 KB)