Skip to content Skip to sidebar Skip to footer

How To Convert List Of Json Frames To Json Frame

I want to convert List of JSON object ot Single JSON frame Here is my code for i in user1: name=i.name password=i.password id1=i.id user = { 'name' : name,

Solution 1:

json.dumps() returns a string, so you're append strings to userid—and thus end up with the list of strings shown.

If you want a dictionary of dictionaries using the id as the primary key, all you need is:

users = {i.id: {"name": i.name, "password": i.password} for i in user1}

Solution 2:

What I've done now is

user = {}
name,password,id1 = [],[],[]
user1=session.query(User).all()
for i in user1:
    name=i.name
    password=i.password
    id1=i.id
    user.update({ id1:{
            "name" : name,
            "password" : password,
          }
        })

Thanks all for your support

Post a Comment for "How To Convert List Of Json Frames To Json Frame"