Flask Jsonify Print Results On New Lines
First time using Flask, I have created a very basic app and I am trying to print the results of a recommender system. The first set of code is from my python function (print_most_s
Solution 1:
Summary
- Answer:
<br>
- Alternative: JSONView Chrome Extension
The only one that give me good results was <br>
:
Example
from flask import Flask, jsonify
app = Flask(__name__)
tasks = [
{
'<br>id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
},
{
'<br>id': 2,
'title': u'Learn Python',
'description': u'Need to find a good Python tutorial on the web',
'done': False
}
]
@app.route('/todo/api/v1.0/tasks', methods=['GET'])defget_tasks():
return jsonify({'tasks': tasks})
if __name__ == '__main__':
app.run(debug=True)
In your browser the <br>
character will be rendered as html and reproduce a new line.
Result: "creates" new lines in json
Jsonify can't help you because it takes the values (integer,boolean,float, etc) as a string and avoid special characters like \n
, \t
, etc
Finally, if you just want a fancy way to visualize json files in your browser, you could use JSONView, is a Chrome extension that render Json files in a more understandable way, like this.
Post a Comment for "Flask Jsonify Print Results On New Lines"