I have a For loop that extracts objects from your database query. Now I'm looking for a way to add these objects to an existing JSON string.
My list looks like this:
i = [(2, 23322323, 'object1name', 'example1'),(3, 2323232, 'object2name', 'example2'),(4, 12312312, 'object3name','example3')]
My For loop looks like this:
count = 1
for item in i:
object = item[2], item[3]
print("Object",count, item[2], item[3])
count = count + 1
My JSON String looks like this:
payload = json.dumps({'intent': 'test', 'message': message, 'url':imageURL})
I would like to have the following JSON output:
payload = json.dumps({'intent': 'test', 'message': message, 'url':imageURL, 'objetc1':object1, 'object2': object2})
I have tried to add the objects with:
payload['object'] = item[2], item[3]
But unfortunately I don't know how to add all objects and additionally the ascending numbering so Object1, Object2 and so on.
Thanks for your help.