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

Hello tstack,

I am trying to something similar, however, it is not working for me. I have a Json field that is comma-delimited named “instructors”. Sometimes this field contains one instructor id number, and sometimes it contains two. I would like these to go into separate table columns of Instructor1 and Instructor2.

I my instructor mapper I did:
image

and my second mapper I did:
2ndmapper

My pipeline validates, however, there is no output from my second mapper.

I would greatly appreciate any assistance you can provide.

Thanks,
sawierman

Did you enable Passthrough on the second mapper?

Hi tstack,

When I enabled Pass through, I was able to see all the fields, including the newly-created Instructor1 and Instructor2 fields!
J

369854d4f34c29026afd038cd8db454137154fa8.jpeg

Now I am struggling with my next step, which is to include other fields from the JSON and insert them into an Oracle table. To start, I wanted to just insert
the ID field and 2 instructor fields to keep things simple.

I thought that if I mapped only the fields I wanted, that it would insert those into the Oracle table, however, I get an error on a field I’m not trying to insert.

63b28feb5b9965ff68f2f6ab0103a9961c13014a.jpeg

f9d8ff68cb69911486d62b6bfd1208e6a9a91899.jpeg

Thinking the Pass Through tries to insert all fields even if they’re not mapped, I un-checked Pass-Through, however, now I am only getting the ID field, but not
the Instructor fields:

2545f7fe0342e52a636bd46f43e3c0c1af60fb91.jpeg

Any suggestions?

Thanks,

Sandy