Skip to content

Instantly share code, notes, and snippets.

@jakbin
Created November 9, 2021 13:01
Show Gist options
  • Save jakbin/826195885cecec6604d7fd93b75f6932 to your computer and use it in GitHub Desktop.
Save jakbin/826195885cecec6604d7fd93b75f6932 to your computer and use it in GitHub Desktop.
download or stream json file from flask server

download or stream json file from flask server

you can return json file from your flask server without creating it.

from flask import Flask, Response, json
app = Flask(__name__)
data = {'name':'jakbin', 'age':24}
# you can generate dynamic json data
a = 'jak'
@app.route('/')
def home():
return Response(json.dumps(data, indent=3), mimetype='application/json',
headers={'Content-Disposition':f'attachment;filename={a}.json'})
# you can generate dynamic file name
if __name__ == "__main__":
app.run(debug=True,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment