Q:

How to wrap REST API response with Wrapper object in Python Flask

While building REST API with flask-restful I'm getting unwanted json array in my response
{
    "data": [
        {
            "email": "sam@test.com",
            "id": null,
            "name": "Sam"
        },
        {}
    ]
}

What I wanted was 
{
    "data": {
         "email": "sam@test.com",
         "id": null,
         "name": "Sam"
    }
}

Here is my code
class User(db. Model):
    id = db. Column(db. Integer, primary_key=True, autoincrement=True)
    name = db. Column(db. String(100), nullable=False)
    email = db. Column(db. String(100), nullable=False, unique=True)
    password = db. Column(db. String(100), nullable=False)

class UserSchema(ma. ModelSchema):
    class Meta:
        model = User
        fields = ('id', 'name', 'email')
        ordered = True

class AuthResource(Resource):
    def post(self):
        parser = reqparse. RequestParser()
        parser.add_argument('name', type=str, required=True, help='name required')
        parser.add_argument('email', type=str, required=True, help='email required')
        parser.add_argument('password', type=str, required=True, help='password required')
        args = parser.parse_args()

        try:
            user = User(**args)
            db.session.add(user)
            db.session.commit()
            return {'data': UserSchema().dump(user)}, 201
        except IntegrityError:
            return {'message': 'Account already exists'}, 400

A:

This did the trick
return {'data': UserSchema().dump(user).data}, 201

