mysql is not returning a list of objects in flask

Viewed 36

I'm working with MySQL and flask, but when I get the data from MySQL, instead of returning a list of objects, is returning a list of lists. how can I solve this?

this is what I'm getting now:

[
   ['John', 'Dohnson', 25],
   ['James', 'Damond', 31]
]

this is what I need:

[
   {name: 'John', lastname: 'Dohnson', age: 25},
   {name: 'James', lastname: 'Damond', age: 31}
]

this is my code now:

@app.route('/')
def getUsers():
    cur = mysql.connection.cursor()
    cur.execute('SELECT * FROM users')
    data = cur.fetchall()
    return jsonify(data)
0 Answers
Related