I have a simple code to fetch users from db using sqlalchemy and return them as json. My problem is how to format the output to get something like this:
{"results": [{"id":1, "username":"john"},{"id":2,"username":"doe"}]} my code outputs an error which I cant seem to fix being a newbie in python:
d = [] for user in Users.query.all(): v = {} for columnName in Users.__table__.columns.keys(): v[columnName] = getattr( user, columnName ) d.append( v ) return jsonify( d ) The code says:
ValueError: dictionary update sequence element #0 has length 11; 2 is required Thanks.
__table__), there are other ways to get that metadata, using the API plus some helpers.