Json is popular data interchange format.It's widely adopted in many programming languages.

Flask supports json. You must import json.


from flask import json

It is pythons default json library. You can check out more about json using the below link

https://docs.python.org/3.4/library/json.html

json.dumps() method is used to generate json format as output.


@app.route('/getjson')
def getjson():
    return json.dumps({"name":"king","likes":"batman"})

 Complete code:


from flask import Flask,json

app = Flask(__name__)

@app.route('/getjson')
def getjson():
    return json.dumps({"name":"king","likes":"batman"})

if __name__ == '__main__':
    app.run(debug=True)