Search This Blog

Tuesday, July 9, 2019

Python - Construct Json in loop

data={}
for  weightagesObj in weightagesAllObject:
        item = {"weight":weightagesObj.weight, "rank":weightagesObj.rank}
        data[weightagesObj.scrip] = item
nseJson=json.loads ( json.dumps(data) )
print ( nseJson["scrip name"] )



{
"RELIANCE": {
"weightage": 9.04,
"rank": 1
},
"TATAMOTORS": {
"weightage": 9.01,
"rank": 2
}
}

No comments:

Hit Counter


View My Stats