Apr-26-2021, 06:06 PM
(This post was last modified: Apr-26-2021, 07:02 PM by masterAndreas.)
Say i have a list of unlabeled tuples which i want to convert to JSON
Where each tuple is an object (of the same type) which represents a user
the first value of the tuple represents a 'username' and second a 'role'
Sample Input:
i can convert one tuple with:
Thanks!
P.S. i am python newbie, but i am familiar with the basic concepts (like syntax)
Where each tuple is an object (of the same type) which represents a user
the first value of the tuple represents a 'username' and second a 'role'
Sample Input:
[('Andy', '001'), ('Off0', '010'), ('Pla0', '100'), ('Pla1', '100'), ('Pla2', '100'), ('Pla3', '100')]Output:
Output:[
{
"username": "Andy",
"role": "001"
},
{
"username": "Off0",
"role": "010"
},
{
"username": "Pla0",
"role": "100"
},
{
"username": "Pla1",
"role": "100"
},
{
"username": "Pla2",
"role": "100"
},
{
"username": "Pla3",
"role": "100"
},
]
Note: i do not care about the white spacesi can convert one tuple with:
json.dumps({'username':list[0][0], 'role':list[0][1]})but i do not understand to conbine all the tuples of the list together
Thanks!
P.S. i am python newbie, but i am familiar with the basic concepts (like syntax)