Skip to content

Instantly share code, notes, and snippets.

@retrofox
Created March 7, 2012 19:54
Show Gist options
  • Save retrofox/1995616 to your computer and use it in GitHub Desktop.
Save retrofox/1995616 to your computer and use it in GitHub Desktop.
res.json = function(obj, headers, status){
var body = JSON.stringify(obj)
, callback = this.req.query.callback
, jsonp = this.app.enabled('jsonp callback');
this.charset = this.charset || 'utf-8';
this.header('Content-Type', 'application/json');
if (callback && jsonp) {
this.header('Content-Type', 'text/javascript');
body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');';
}
return this.send(body, headers, status);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment