I am trying to write a list of json objects to a file in google cloud using python. I am able to write a single object in the file. But it is not working when I try to write it in a for loop.
Here is the code which works for a single object but does not work when i write iteratively
from google.cloud import storage
import json
bucket_name = 'gcs_bucket_user'
bucket = storage.Client().get_bucket(bucket_name)
for i in range(0,5):
json_object = {'i': 'i'}
blob = bucket.blob('text.json')
blob.upload_from_string(data=json.dumps(json_object),content_type='application/json')
Expected Output
{'0':'0'}
{'1':'1'}
{'2':2}
and so on
But this is not appending objects in the json file. It is overwriting them.
Also what is the way to iteratively read json objects from such a file in google cloud