Sends the given object (or array) as JSON.

@param   {Request}       req
@param   {Response}      res
@param   {function}      next
@param   {object|array}  obj
544820
function sendObject (req, res, next, obj) {
  setContentType(req, res, ["json", "*/json", "+json"]);

  util.debug("Serializing the response as JSON");
  res.json(obj);
}
994201
function processResponse(obj) {
	for (var p in obj.nitro.results.items) {
		var partner = obj.nitro.results.items[p];
		console.log(partner.pid+','+partner.name+','+(partner.description||'No description'));
	}
	var dest = {};
	if ((obj.nitro.pagination) && (obj.nitro.pagination.next)) {
		dest.query = nitro.queryFrom(obj.nitro.pagination.next.href,true);
		dest.path = path;
		dest.callback = processResponse;
	}
	nitro.setReturn(dest);
	return true;
}
1061519
function serveRemoteJson(request, response, next) {
	if (request.path !== '/remote') {
		return next();
	}
	var options = {
		url: request.query.url,
		headers: request.query.headers
	};
	var error;

	if (!options.url || typeof options.url !== 'string') {
		error = new Error('Invalid query parameter: url');
		error.status = 400;
		return next(error);
	}

	if (options.headers && typeof options.headers !== 'string') {
		error = new Error('Invalid query parameter: headers');
		error.status = 400;
		return next(error);
	}

	options.headers = parseHeaders(options.headers);

	loadRemoteJson(options, function (error, json) {
		if (error) {
			return next(error);
		}
		response.writeHead(200, {
			'Content-Type': 'application/x-shunter+json'
		});
		response.end(JSON.stringify(json, null, 4));
	});
}
229093
function serviceCall(req, res, next) {
        connector.runCall(req.params.connection, req.params.call, req.body).then(res.json.bind(res), next).done();
    }
1349552
def put(request, obj_id):
    
    res = Result()
    c = Comment.objects.get(pk=obj_id)
    data = request.PUT or json.loads(request.body)['body']
    content = data.get('comment', None)
    if content:
        c.comment = content
        c.save()

        res.append(commentToJson(c))

    return JsonResponse(res.asDict())
607122
function trySendOptionsResponse(res, methods, next) {
  try {
    sendOptionsResponse(res, methods)
  } catch (err) {
    next(err)
  }
}
556488
function handleAny (obj) {
    if (isPromiseAlike(obj)) {
      return obj.then(handleAny)
    } else if (isPlainObject(obj)) {
      return handleObject(obj)
    } else if (Object.prototype.toString.call(obj) === '[object Array]') {
      return handleArray(obj)
    } else {
      return new Promise(function (resolve, reject) {
        return resolve(obj)
      })
    }
  }
1182113
@Post("/node/obj")
    @ProducesJson
    public Response json2(@RequestObject JsonNode input) {
        final JsonNode name = input.get("name");
        return new Response(Response.SUCCESS, name.textValue());
    }
455807
function transform(req, res, next) {
    const state = res.state;
    const body = state.body;
    const type = typeof body;
    const isBuffer = body instanceof Buffer;
    let contentType;

    // error conversion
    if (body instanceof Error) {
        res.log('transform', 'Converting Error to response');
        res.status(500).body(httpStatus[500]).set('content-type', 'text/plain');

    // buffer conversion
    } else if (isBuffer) {
        res.log('transform', 'Converting Buffer to base64 string');
        res.body(body.toString('base64'));
        contentType = 'application/octet-stream';

    // object conversion
    } else if (type === 'object') {
        res.log('transform', 'Converting object to JSON string');
        res.body(JSON.stringify(body));
        contentType = 'application/json';

    // not string conversion
    } else if (type !== 'string') {
        res.log('transform', 'Converting ' + type + ' to string');
        res.body(String(body));
        contentType = 'text/plain';

    } else {
        contentType = 'text/html';
    }

    // set content type if not yet set
    if (!state.headers.hasOwnProperty('content-type') && contentType) {
        res.log('transform', 'Set content type');
        res.set('Content-Type', contentType);
    }

    next();
}
734808
function update(req, res, next) {
  var body = req.body;
  delete body.username;

  db.users.update(req.params.user, body, function(err, user) {
    if(err) { return next(err); }
    res.json(201, user);
  });
}
1302732
def _attach_obj(self, req, obj):
        """"""

        # Attach the object to the request
        json.dump(obj, req)

        # Also set the content-type header
        req['content-type'] = self._content_type
685256
function clone(req, res, next) {
  var cloneFormParams = {
    _id: req.params.id,
    name: req.body.name,
    userEmail: req.body.updatedBy
  };

  logger.debug("Middleware: clone form: ", {params: cloneFormParams});

  forms.cloneForm(_.extend(req.connectionOptions, cloneFormParams), formsResultHandlers(constants.resultTypes.forms, req, next));
}
1295227
function(request, response, next){
		if (utils.Misc.isEmptyObject(request.query)) {
			var errApp = new Error(errors['130']);
			response.end(utils.Misc.createResponse(null, errApp, 130));
		}
		else {
			next();
		}
	}
840673
function(req, res, fromMessage) {
            var name = req.params.name;
            var doc  = req.body;
            // if this is an array
            if (Array.isArray(doc)) {
                var error, data = [];
                var count = 0, len = doc.length;
                if (len > 0) {
                    var resp = {
                        send: function(code, response) {
                            count++;
                            response = response || code;
                            if (typeof response === 'object') {
                                data.push(response);
                            } else {
                                error = response;
                            }
                            if (count >= len) {
                                if (data.length > 0) {
                                    res.send(data);
                                } else {
                                    res.send(400, error);
                                }
                            }
                        }
                    };
                    for (var i = 0; i < len ; i++) {
                        this.createOne(name, doc[i], fromMessage, resp);
                    }
                } else {
                    res.send(data);
                }
            } else {
                this.createOne(name, doc, fromMessage, res);
            }
        }
529937
def _write_json(obj, path):  # type: (object, str) -> None
    """"""
    with open(path, 'w') as f:
        json.dump(obj, f)
12094
function (item, req, eachReq, res, next) {
          eachReq.item = item;
          eachReq[indexKey] = index;
          index++;
          next();
        }
862050
function serveErr(_req, res, next) {
    return async function (err) {
        if (err.message === 'next') {
            return next();
        }
        console.log('ERROR', err);
        console.log('STACK', err.stack);
        let text = 'ERROR' + (err.code ? ' ' + err.code : '') + ': ' + err.message;
        exports.globalOpts.serveErr.propertiesWhiteList.forEach(function (attrName) {
            if (attrName in err) {
                text += '\n' + attrName + ': ' + JSON.stringify(err[attrName]);
            }
        });
        if (exports.globalOpts.serveErr.sendStack) {
            text += '\n------------------\n' + err.stack;
        }
        if (!res.headersSent) {
            let buf = new Buffer(text);
            let length = buf.length;
            res.writeHead(err.status || 400, {
                'Content-Length': length,
                'Content-Type': 'text/plain; charset=utf-8'
            });
        }
        else {
            text += "\n</script>\n<pre>\n------------------------------------\n" + text;
        }
        res.end(text);
    };
}