I need to create collections of JSON objects from REST requests (see post Talend - URI based on values obtained from a list). A webservice provides a collection of agencies in the following format:
{ "COD_AGENCIA":"521800300", "NAME":"AGENCIA01"},
{ "COD_AGENCIA":"521999999", "NAME":"AGENCIA02"},
...
(20 other values)
...
Another webservice, from an agency code, provides the cities related to this agency, in the following format:
{"COD_MUN":"5202155","NOME_MUN":"CITY01"},
{"COD_MUN":"5202502","NOME_MUN":"CITY02"},
...
I created a job that gets the agency relationship, and through a tFlowToIterate, I call multiple requests through a tRest, varying the agency code. My job is like this:
When I turn on the output of the last tExtractJSONField in a tLog, the codes and names of all the cities at once they are printed. If I change the tLog for a tFileOutputJSON, the final file contains only the last iteration called cities.
What I need to change to be able to generate in a single job multiple JSON objects in the following format:
{"COD_AGENCIA":"521800300",
"NAME":"AGENCIA01",
"CIDADES":[{"COD_MUN":"5202155","NOME_MUN":"CITY01"},
{"COD_MUN":"5202502","NOME_MUN":"CITY02"}
]
}
{"COD_AGENCIA":"521999999",
"NAME":"AGENCIA02",
"CIDADES":[{"COD_MUN":"5244887","NOME_MUN":"CITY03"},
{"COD_MUN":"5254522","NOME_MUN":"CITY04"}
]
}