var http = require('http'); var NG_PREFIX = ")]}',\n"; http.ServerResponse.prototype.ngJSON = function(obj){ // allow status / body if (2 == arguments.length) { // res.json(body, status) backwards compat if ('number' == typeof arguments[1]) { this.statusCode = arguments[1]; } else { this.statusCode = obj; obj = arguments[1]; } } // settings var app = this.app; var replacer = app.get('json replacer'); var spaces = app.get('json spaces'); var body = JSON.stringify(obj, replacer, spaces); // content-type this.get('Content-Type') || this.set('Content-Type', 'application/json'); return this.send(NG_PREFIX + body); }; //e.x. res.ngJSON({ name : 'Tyler' }); //e.x. res.ngJSON(500, { error : 'Something something dark side' });