Converting a set of xml files to a set of json files

One Star

Converting a set of xml files to a set of json files

Hi,
Can somebody help me how to convert a set of xml files from a directory to set of json files.
Thanks
Singh
Moderator

Re: Converting a set of xml files to a set of json files

Hi,
Converting a set of xml files?
Could you please elaborate your case with an example with input and expected output values?

Usually, we use tFileInputXML--main--tWriteJsonField--main-->tFileOutputDelimited to convert XML to json without multiple loop elements.

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Converting a set of xml files to a set of json files

Hi ,
This is what I did. I did this on windows. Talend 5.2
Goal -> Insert xml data files residing in one folder into Mongodb
Design -> tFileList (Orchestration) -> File Xml -> tMongoDBOutput
1. tFileList - Created tFileList giving the folder location e.g c:\input\xml , where some 10,000 xml files under the xml folder.
    I wanted to iterate all the files in this folder
2. I created a new xml file object under the left hand panel File Xml. All the xml files have similar elements and tags but content different.
   Now as I need to map the column names , I dragged in the elements and mapped the columns. I had to select one xml file from this
   xml folder to know the elements as a template file.
3. I created tMongoDBOutput givng the ip and the port and specified the database and the mongo collection.
Result -> When I ran the job, the tFileList is iterating through all the files. But coming to the second step which is xml file which I created in 2 above, It had all the columns I specified but while saving to MongoDB , it inserted some 330 rows with the same document, meaning the same content some 330 times , it just inserted the first file contents only . Other contents from other files where not picked up.
Initially: I though of converting all xml files to it's corresponding json files and then insert into mongodb by iterating, but I did not try to do this.
Instead , I created an iterating file list passed it to xml template, thinking that it will dynamically change and insert each time to mongodb. But this is not working. Xml template I just mentioned is stuck with contents from the first file , the remaining are not getting updated. I thought , the first time tfilelist iterate, it will pick up the first file, then it will pass over the second step which is the xml file step and then store this in mongodb. Now this is working for the first iteration. Remaining it is not working.
Help -> Can you suggest how to iterate a list of files, in the first iteration, the first xml file is passed to second step , maps all the contents or elements and then store it in Mongodb. When the second iteration happens, second file is picked up , passes to xml file step, refreshes it's first contents and copies the second file contents and again store this to mongodb. That way as you iterate all the files , there should be say 10,000 different rows or documents in mongodb.
Which component should I use for this use case.
Regards
Singh