Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
@Hemanth Vasa , tWriteJsonField does not support multiple loop elements.
Regards
Shong
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
What's your next step after generate the Json string? Output it to a Json file or call a webservice?
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
@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.
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.
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