Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Created September 29, 2011 23:23
Show Gist options
  • Save gregorynicholas/1252216 to your computer and use it in GitHub Desktop.
Save gregorynicholas/1252216 to your computer and use it in GitHub Desktop.
Python method decorator for appengine to ouput json to response.
def jsonresult(func):
'''
Decorator that sets response headers to output json data.
'''
def _func(self, *args, **kwargs):
self.response.headers['Content-Type'] = "text/plain"
logging.debug('--- Outputting JSON Result ---')
result = func(self, args, kwargs)
self.response.out.write(json.dumps(result))
return _func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment