I am using the following python code to return a json object:
df_as_json = df.to_json(orient='split')
return jsonify({'status': 'ok', 'json_data': df_as_json})
When I read the object back in javascript:
// response is xhr respose from server
const mydata = response.data
console.log(mydata.constructor.name)
// >Obj
const dfdata = mydata.json_data
console.log(dfdata.constructor.name)
// >String
Is there a way to send the df_as_json as a json object inside the parent response.data json object?
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})
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})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With