tMAP: Check for value in an array

Highlighted
Six Stars

tMAP: Check for value in an array

Hello everybody,

 

My datasoruce is a questionnaire and we using a rest API to get the data (json). Now I have a problem with Checkbox questions. For example:

The data source contains a questions with 5 answers. Each answer has it's own checkbox. If someone choose 3 of them, I get an value array with 3 of 5:

 

"What are your plans for today?.": [
"Stay at home",
"Working ",
"Eat, sleep, repeat"
],

 

So in tMap the field of the input table is the question " What are your plans for today?" and the values are "Stay at home","Working ","Eat, sleep, repeat". But the Output table should have a field for each answer possiblity :

Field one: Stayathome

Field two: Working

....

now when I have the case that someone choosed checkbox "Stay at home", I want a "X" in my Output field Stayathome. I've tried to solve that issue with a if expression. But it doesn't work. So Talend has the check, if the array inlcudes "Stay at home" (i.e.). If true "X", else "  ".  Does anyone have a solution approach?

 

thanks,

Christian


Accepted Solutions
Highlighted
Seven Stars

Re: tMAP: Check for value in an array

I think a conditional operator is ideal for your scenario.

You should be able to include something like this in your tmap expression assuming your column datatype is string,

row1.plans.toLowerCase().contains("stay at home")?"X":"" 

plans.PNG

 

 

 

 

 

View solution in original post


All Replies
Highlighted
Seven Stars

Re: tMAP: Check for value in an array

I think a conditional operator is ideal for your scenario.

You should be able to include something like this in your tmap expression assuming your column datatype is string,

row1.plans.toLowerCase().contains("stay at home")?"X":"" 

plans.PNG

 

 

 

 

 

View solution in original post

Highlighted
Six Stars

Re: tMAP: Check for value in an array

Hello,

 

I've already got it. But you're right.

 

Cheers,

Christian

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog