flask import json code example

Example 1: flask import jsonify

from flask import jsonify

@app.route('/_get_current_user')
def get_current_user():
    return jsonify(username=g.user.username,
                   email=g.user.email,
                   id=g.user.id)

Example 2: how to return json response in flask

from flask import jsonify

@app.route('/summary')
def summary():
    d = make_summary()
    return jsonify(d)

Example 3: flask api with parameter

args = request.args
print (args) # For debugging
no1 = args['key1']
no2 = args['key2']
return jsonify(dict(data=[no1, no2])) # or whatever is required