pandas to_json returns a string not a json object
Just return dict and let jsonify convert dict to string.
df_as_json = df.to_dict()
return jsonify({'status': 'ok', 'json_data': df_as_json})
There's no such thing as a "json object" in python that's why.to_json
returns a string representation of the json object, json in python is essentially the same as a dict
, you can use the to_dict
method instead.
df_as_json = df.to_dict(orient='split')
return jsonify({'status': 'ok', 'json_data': df_as_json})