Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created October 25, 2012 13:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save johnschimmel/3952666 to your computer and use it in GitHub Desktop.
Save johnschimmel/3952666 to your computer and use it in GitHub Desktop.
Sample of Flask receiving JSON
# If /json route receives header "application/json"
@app.route("/json", methods=['GET','POST'])
def json():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
mydata = request.json # will be
return "Thanks. Your age is %s" % mydata.get("age")
else:
return "no json received"
@mre
Copy link

mre commented Jan 15, 2019

Just in case people are having problems using this code, your request content type needs to be application/json. Otherwise you get None as the parsed value. https://stackoverflow.com/a/20001283/270334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment