Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to create a collection of JSON objects

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 attached below.

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"}
  ]
}

0683p000009MFZE.png
Labels (4)
1 Reply
Anonymous
Not applicable
Author

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.


You are using tFlowToIterate to iterate each record, it will always generate a new file for each record. To fix it, use a tUnite to merge all the records before writing them to a file. eg:
...tExtractJSONFields-tUnite-main--tFileOutputJSON

Regards
Shong