Skip to content

Instantly share code, notes, and snippets.

@kamens
Created January 14, 2013 20:26
Show Gist options
  • Save kamens/4533077 to your computer and use it in GitHub Desktop.
Save kamens/4533077 to your computer and use it in GitHub Desktop.
jsonify proposals
###############################
# Proposal 1:
@jsonify
def monkey_function():
if gorillas:
# JsonResponse is a new function you'll write that will wrap this in a flask response object,
# so @jsonify's code, as-is, will know not to do anything to it
return JsonResponse(subtitles.json)
else:
# in this case @jsonify's code, as-is, will do its thing and automatically turn this into "null"
return None
###############################
# Proposal 2:
def monkey_function():
if gorillas:
# not using @jsonify, so we can just return JSON
return subtitles.json
else:
# manually JSONifying "None" in this case, instead of using the @jsonify wrapper
return api.jsonify.jsonify(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment