I'm trying to make a response using Flask from a Mongodb collection:
@app.route('/stories', methods = ['GET'])
def get_stories():
stories = db.stories.find()
json_docs = [json.dumps(doc, default=json_util.default) for doc in stories]
resp = jsonify(data=json_docs)
resp.status_code = 200
return make_response(resp)
This gets all the items and encodes it into a JSON response, but it looks like this:
{
"data": [
"{\"content\": \"some story here\", \"_id\": {\"$oid\": \"5293c34431e20307544db9cb\"}}",
"{\"content\": \"some story here\", \"_id\": {\"$oid\": \"5293c34d31e20307584c3e6e\"}}",
"{\"content\": \"some story here\", \"_id\": {\"$oid\": \"5293c57d31e20307a7b40abe\"}}"
]
}
Is there a way to encode this using single quotes so it doesn't add in the escape strings? Or is there something I'm overlooking