Four Stars

How to create nested json array through talend job?

Hello,

 

My requirement is to create json message as an output which will have nested array list. I tried to achieve it using twritejsonfield component but this supports only one loop element. Do we have some provision in talend which will allow us to set multiple elements but nested ones as loop elements through which I may achieve desired output:

 

Output Message Generated:

{"navDate":"2018-06-19T00:00:00",
"clients":
[
{"name":"SLB","fundGroups":{"name":"IBOR-DALY","funds":{"name":"I0AO","rules":{"systemName":"Valuation","startdate":"2018-06-20T10:00:00"}}}},
{"name":"SLB","fundGroups":{"name":"IBOR-DALY","funds":{"name":"I247","rules":{"systemName":"Valuation","startdate":"2018-06-19T10:00:00"}}}},
{"name":"SLB","fundGroups":{"name":"IBOR-DALY","funds":{"name":"I520","rules":{"systemName":"Valuation","startdate":"2018-06-20T10:00:00"}}}}
]
}

 

Desired Output Message:

{"navDate":"2018-06-19T00:00:00",
"clients":
[ {"name":"SLB","fundGroups":[{"name":"IBOR-DALY","funds":[{"name":"I0AO","rules":[{"systemName":"Valuation","startdate":"2018-06-20T10:00:00"}]},{"name":"I247","rules":[{"systemName":"Valuation","startdate":"2018-06-19T10:00:00"}]},{"name":"I520","rules":[{"systemName":"Valuation","startdate":"2018-06-20T10:00:00"}]}]}]}
]
}

2 REPLIES
Nine Stars

Re: How to create nested json array through talend job?

Not really sure how to achieve what you want ...
I use tXMLMap, create a column of Document type and aggregate and loop on the lowest level, like this structure:
-- out
---- navData
---- clients
--------- name <---- aggregate
--------- fundgroups
----------------- name
----------------- funds
-------------------- name <--- loop level
-------------------- rules
------------------------- systemName 
------------------------- startdate

Seven Stars

Re: How to create nested json array through talend job?

Hi,
I faced the same scenario couple of years back. Then, first I created the nested XML, then I converted the XML generated to the JSON using the java classes in tJavaRow component.

I hope that could give you a solution, Also what I could remember is I was not able to achieve it using the tWriteJsonFields.

Best Regards,
Abhishek