0

I have data in python as a=[{a:1,b:1},{a:3,b:3}]. How can I write these JSON in S3 (boto3) as file directly in Python?

1
  • What have you tried already to write JSON data to S3? Where will your python code run to write the data as you may need to consider access policies as well. Commented Sep 27, 2021 at 10:23

1 Answer 1

3
import json
import boto3

s3 = boto3.client('s3')
a=[{"a":1,"b":1},{"a":3,"b":3}]
s3.put_object(
     Body=json.dumps(a),
     Bucket='your_bucket_name',
     Key='your_key_here'
)
Sign up to request clarification or add additional context in comments.

3 Comments

thanks, will the file contains only {a:1,b:1} {a3:,b3} not the array [{"a":1,"b":1},{"a":3,"b":3}]
You can read the json and pass to body without json.dump() if it's already str
I have tried this, it is writing as array of json values, but how to append json records in a file without array? can you help me ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.