Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python aws botocore.response.streamingbody to json

I am using boto3 to acccess files from S3, The objective is to read the files and convert it to JSON But the issue is none of the files have any file extension (no .csv,.json etc),although the data in the file is structured like JSON

client = boto3.client(
    's3',
    aws_access_key_id = 'AKEY',
    aws_secret_access_key = 'ASAKEY',
    region_name = 'us-east-1'
)
obj = client.get_object(
    Bucket = 'bucketname',
    Key = '*filename without extension*'
)

obj['Body'] returns a <botocore.response.StreamingBody> object

is it possible to find out the data within it?

like image 525
Devarshi Goswami Avatar asked Feb 21 '26 19:02

Devarshi Goswami


1 Answers

The extension does not matter. Assuming your file contains valid json, you can get it:

my_json = json.loads(obj['Body'].read())
like image 55
Marcin Avatar answered Feb 24 '26 15:02

Marcin