0

I have my bucket structure like below and i have xml files landing in this s3 bucket folder.

S3:/Fin-app-ops/data-ops/raw-d

Need to convert those xml files to JSON files and put back to s3 in same bucket but different folder: S3:/Fin-app-ops/data-ops/con-d

I tried by this way but did not work:

import os
import json
import boto3
import xmltodict

s3 = boto3.resource('s3')
s3_bucket = s3.bucket('Fin-app-ops')

file_in_path = 'data-ops/raw-d/'
file_dest_path = 'data-ops/con-d/'

Datafiles = [f.key for f in s3_bucket.objects.filter(prefix = file_in_path)]

for datafile in datafiles:
    if "xml" in obj.key:
        datafile = obj.get()['Body']
        data_dict = xmltodict.parse(datafile .read())
        datafile.close()
        json_data = json.dumps(data_dict)
        s3.Object(bucket_name, file_dest_path `enter code here`+'.json').put(Body=json.dumps(data_dict))

is there any other way I can achieve this, help please i'm new to Python and Glue

Sarath
  • 35
  • 3

0 Answers0