Merge two strings from a Json loop into one

Six Stars

Merge two strings from a Json loop into one

I am trying to merge two strings from a Json loop into one. I have the following components in play at present. 

 

tFileInputJson-->tMap-->tFileOutputDelimited. 

 

My input json document looks like

{
"columns": {
"source": "config",
"column_details": [{
"columnname": "col2",
"datatype": "float"
},
{
"columnname": "col3",
"datatype": "integer"
}
]
}

}

 

I would like to create a string in tFileOutputDelimited as 

"The result set is

convert col2 to float

convert col3 to integer"

 

However due to the loop XPath query parameter being set to "/columns/column_details" in tFileInputJson and creating the string in tMap with columnname and datatype. I get the following output 

The result set is

convert col2 to float

The result set is

convert col3 to integer

 

Any help is appreciated. Thanks


Accepted Solutions
Ten Stars

Re: Merge two strings from a Json loop into one

Look at the tJavaFlex component, you have to code some java but pretty easy.
Something like below (didnt test the java code).

 

Basicly in the Pre part you set: 

String fullString = "The result set is ";

In the Main part (this will loop over all the rows) , you set :

fullString = fullString + "convert " + row.columnname + " to " + row.datatype + "\n"

 

View solution in original post


All Replies
Ten Stars

Re: Merge two strings from a Json loop into one

Look at the tJavaFlex component, you have to code some java but pretty easy.
Something like below (didnt test the java code).

 

Basicly in the Pre part you set: 

String fullString = "The result set is ";

In the Main part (this will loop over all the rows) , you set :

fullString = fullString + "convert " + row.columnname + " to " + row.datatype + "\n"

 

View solution in original post

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog