Skip to content

Instantly share code, notes, and snippets.

@pcote
Created December 16, 2015 03:28
Show Gist options
  • Save pcote/37e51134d50b47802258 to your computer and use it in GitHub Desktop.
Save pcote/37e51134d50b47802258 to your computer and use it in GitHub Desktop.
def validate_json(*expected_args):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
json_ob = request.get_json()
for expected_arg in expected_args:
if expected_arg not in json_ob or json_ob.get(expected_arg) is None:
abort(400)
return func(*args, **kwargs)
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment