I am developing an API using flask-RESTful and am having an issue with Flask's jsonify function. I am using flask-marshmallow for JSON serialization. Below is a very simplified code snippet:
result = activities_schema.dump(activities)
return jsonify(result)
Locally, the endpoint will return json that has keys 'data' and 'errors'; however, when running on a Linux server, this returns a result that contains a list and a dict, without the 'data' and 'errors' keys.
I have determined this inconsistency is caused by Flask's jsonify function by printing out results before they are returned by the API. Both locally and on the server, 'result' equals:
MarshalResult(data=[], errors={})
However, when I print the response after using Flask's jsonify, I get this locally:
('{\n "data": [], \n "errors": {}\n}', '\n')
while this is printed on the server:
('[\n [], \n {}\n]', '\n')
Anyone know why these don't match?
Marshmallow >= 3
, schemas are always strict: notes on upgrading – el.atomo