Home > Net >  List to a json object
List to a json object

Time:05-26

I have a list of ec2 instanceID like below:

['i-111111111111', 'i-22222222222']

And I want to convert it to json.

{
  "instance_id": "i-111111111111",
  "instance_id": "i-222222222222"
}

Can someone please advise how to do it in Python?

CodePudding user response:

li = ['i-111111111111', 'i-22222222222']
di = dict()
for i in li:
   a = {'instance_id':i}
   di.update(a)
print(di)

But having a single key is not a good approach

  • Related