Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
HVasa1630039830
Contributor
Contributor

How to set multiple loop elements in twritejsonfield component

Hi ,

iam new to talend and was looking to see if the below can be achieved while generating json through tWriteJsonfield component

My json object has below format:

{

"id": "123",

"Name": "tya",

"dept": [{

"type": "retere22",

"rel": "from"

}, {

"type": "retere27",

"rel": "from"

}],

"prodcts": [{

"prdname": "aquea",

"prodtype": "Inde"

}, {

"prdname": "trewre",

"prodtype": "usasr"

}],

}

i was able to created one loop element by using group by in component properties for dept object on type value

but is their a way to set another loop element for prodcts array as well .. please suggest some way to achieve the same

Regards,

Sai

Labels (4)
7 Replies
Anonymous
Not applicable

@Hemanth Vasa​ , tWriteJsonField does not support multiple loop elements.

 

Regards

Shong

HVasa1630039830
Contributor
Contributor
Author

HI thanks for the reply .. is their any other way to achieve the same instead of twritejsonfield

 

Could you please advice or guide on how to achive json with multiple loop elements

Anonymous
Not applicable

What's your next step after generate the Json string? Output it to a Json file or call a webservice?

 

HVasa1630039830
Contributor
Contributor
Author

Hi Shong,

 

Sorry for the delayed reply .. my output is to a json file which inturn iam converting to a byte and sending it to kafka component .. in precise i will be sending that json in kafka .. so it will connect to kafka component

 

Any advice on how to achieve the same

Anonymous
Not applicable

@Hemanth Vasa​ , as the twriteJsonField does not support multiple loop elements, have a try other way:

First, twriteJsonField generate the first part string

{

"id": "123",

"Name": "tya",

"dept": [{

"type": "retere22",

"rel": "from"

}, {

"type": "retere27",

"rel": "from"

}]

}

Then, use another tWriteJsonField generate the second part of string like

{"prodcts": [{

"prdname": "aquea",

"prodtype": "Inde"

}, {

"prdname": "trewre",

"prodtype": "usasr"

}],

}

Link two part of strings to form a string and output it to a file, before doing this step, delete or add some characters from the two part of strings to be able to generate the required json string.

 

 

tnewbie
Creator II
Creator II

However it may turn out to be a very weird way of handling data. In a complex JSON, there can be more arrays and the purpose can easily be defeated. However for a determined scenario, approach looks to be a good work around.

Anonymous
Not applicable

One way to create complex json is using custom components like these here:

https://exchange.talend.com/#marketplaceproductoverview:marketplace=marketplace%252F1&p=marketplace%252F1%252Fproducts%252F1438&pi=marketplace%252F1%252Fproducts%252F1438%252Fitems%252F2982