0

the following is the code to convert single files , how to work if there are multiple xml files:

import xmltodict
import json
with open("demo.xml") as xml_file:
    data_dict = xmltodict.parse(xml_file.read())
    json_data = json.dumps(data_dict)
    with open("datas.json", "w") as json_file:
        json_file.write(json_data)

Im getting correct output for single file but how to execute for many files

  • Wrap `with open(....)` in a for loop `for f in fileList: with open(f) as xml_file: ....` – LMC Nov 16 '22 at 19:04
  • i need to do it for s3 bucket , i dont think it will work , as the bucket object can be itreated – Nisha naik Nov 17 '22 at 16:59
  • May be it can ;-) https://stackoverflow.com/questions/3337912/quick-way-to-list-all-files-in-amazon-s3-bucket – LMC Nov 17 '22 at 17:48

0 Answers0