The res.json() method takes 3 types of arguments res.json(obj) this is the current best practice res.json(statusCode, obj) this is an older form still accepted res.json(obj, statusCode) this is a crazier form still accepted
177600
function wrappedJson(oldJson, inflectorName){
  let args = Array.prototype.slice.call(arguments, 2);
  if (typeof args[0] === 'object') {
    args[0] = transform(args[0], inflectorName);
  } else if (typeof args[1] === 'object') {
    args[1] = transform(args[1], inflectorName);
  }
  return oldJson.apply(this, args);
}
1129965
async function buildRequest(method, url, params, options) {
  let param = {};
  let config = {};
  if (noneBodyMethod.indexOf(method) >= 0) {
    param = { params: { ...params }, ...reqConfig, ...options };
  } else {
    param = JSON.stringify(params);
    config = {
      ...reqConfig,
      headers: {
        'Content-Type': 'application/json',
        ...csrfConfig,
      },
    };
    config = Object.assign({}, config, options);
  }
  return axios[method](url, param, config);
}
1269222
protected void writeJSON(final HttpServletResponse resp, final Object obj)
      throws IOException {
    writeJSON(resp, obj, false);
  }
671330
def json_or_jsonp( data )
  callback = params.delete('callback')
  response = ''

  if callback
    content_type :js
    response = "#{callback}(#{data.to_json})"
  else
    content_type :json
    response = data.to_json
  end
  
  response
end
1115793
function (res, res_obj) {

    // return response if exist, otherwise response might be returned 
    // AFTER some callback is done handling (i.e., response will be returned within the handler)
    if (typeof res_obj === 'string') {
        LOG.sys('replying a string: ' + res_obj);
        res.writeHead(200, {'Content-Type': 'text/plain'});                     
        res.end(res_obj);            
    }
    else {
        LOG.sys('replying a JSON: ' + JSON.stringify(res_obj));
        res.writeHead(200, {'Content-Type': 'application/json'});                     
        res.end(JSON.stringify(res_obj));        
    }
}
753826
def repr2_json(obj_, **kwargs):
    
    import utool as ut
    kwargs['trailing_sep'] = False
    json_str = ut.repr2(obj_, **kwargs)
    json_str = str(json_str.replace('\'', '"'))
    json_str = json_str.replace('(', '[')
    json_str = json_str.replace(')', ']')
    json_str = json_str.replace('None', 'null')
    return json_str
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);
            }
        }
979022
function (obj, meta, status = 200, errorCode = -1, devMsg = null, usrMsg = null, moreInfo = null) {
      if (res.finished) {
        // request ended
        return
      }

      // ref.: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
      if (status < 300) {
        // OK
        // 
        let body
        switch (typeof obj) {
          case 'object':
            // expected
            if (meta) {
              res.setHeader('X-Metadata', 'true')
              body = JSON.stringify({ 'meta': meta, 'result': obj })
            } else {
              body = JSON.stringify(obj)
            }
            break

          case 'string':
          case 'number':
            // maybe an ID returned after modification request
            body = JSON.stringify({ 'result': obj })
            break

          default:
            // return null JSON object
            body = '{}'
        }

        if (verb === 'GET') {
          // ETag to verify browser cache validation
          // have to be set here, web servers will not etag proxy requests
          // Cloudflare keep only weak ETags
          res.setHeader('ETag', etag(body, { 'weak': true }))
        }
        res.writeHead(status)
        res.end(body)
      } else if (status < 400 && typeof obj === 'string') {
        // redirect
        // expect obj to be the redirect URL
        // return object with previous and next (after redirect) URL
        let response = {
          'status': status,
          'requested_url': req.url,
          'endpoint': obj
        }
        // explain type of redirect in message
        if (status === 301) {
          response.message = 'Moved permanently, please re-send this request to the specified endpoint'
        } else {
          response.message = 'Temporary redirect, re-send this request to the specified temporary endpoint, ' +
            'continue to use the original request endpoint for future requests'
        }

        res.writeHead(status, { 'Location': obj })
        res.end(JSON.stringify(response))
      } else if (typeof obj === 'object' && obj !== null && Object.keys(obj).length > 0) {
        // custom error object
        res.writeHead(status)
        res.end(JSON.stringify(obj))
      } else {
        // client and/or server error
        httpErrorHandling(res, status, errorCode, devMsg, usrMsg, moreInfo)
      }
    }
1332925
def J(*args, **kwargs):
    
    response = jsonify(*args, **kwargs)
    response.mimetype = 'application/vnd.api+json'
    return response
465187
function (req, res) {
		LOG.warn('handle_request');

		// attach custom res methods (borrowed from express)
		res = UTIL.mixin(res, response);

		LOG.sys('HTTP req received, header', 'SR.REST');
		LOG.sys(req.headers, 'SR.REST');
		
		var content_type = req.headers['content-type'];

		// NOTE: multi-part needs to be handled first, because req.on('data') will not be able to process correctly
		if (typeof content_type === 'string' && content_type.startsWith('multipart/form-data; boundary=')) { 
			LOG.warn('parsing form request...', 'SR.REST');
			route(req, res);
			return;
		}
		
		// temp buffer for incoming request
		var data = '';
		var JSONobj = undefined;
		
		req.on('data', function (chunk) {
			data += chunk;
		});

		req.on('end', function () {
			
			var JSONobj = undefined;
			
			try {
				if (data !== '') {
						
					if (content_type.startsWith('application/x-www-form-urlencoded')) {
						JSONobj = qs.parse(data);
					} else if (content_type.startsWith('application/json')) {
						JSONobj = UTIL.convertJSON(decodeURIComponent(data));
					} else if (content_type.startsWith('application/sdp')) {
						JSONobj = data;
					} else {
						var msg = 'content type not known: ' + content_type;
						LOG.warn(msg, 'SR.REST');
						SR.REST.reply(res, msg);
						//res.writeHead(200, {'Content-Type': 'text/plain'});
						//res.end(msg);
						return;
					}
				}
			} catch (e) {
				var msg = 'JSON parsing error for data: ' + data + '\n content_type: ' + content_type;
				LOG.error(msg, 'SR.REST');
				//res.writeHead(200, {'Content-Type': 'text/plain'});
				//res.end(msg);
				SR.REST.reply(res, msg);
				return;
			}

			route(req, res, JSONobj);
		})
	}
254439
function(ajaxOb, data, type, dataType, success, error) {

                var params = {};

                // A string here would be something like `"GET /endpoint"`.
                if (typeof ajaxOb === 'string') {
                    // Split on spaces to separate the HTTP method and the URL.
                    var parts = ajaxOb.split(/\s+/);
                    params.url = parts.pop();
                    if (parts.length) {
                        params.type = parts.pop();
                    }
                } else {
                    // If the first argument is an object, just load it into `params`.
                    can.extend(params, ajaxOb);
                }

                // If the `data` argument is a plain object, copy it into `params`.
                params.data = typeof data === "object" && !can.isArray(data) ?
                    can.extend(params.data || {}, data) : data;

                // Substitute in data for any templated parts of the URL.
                params.url = can.sub(params.url, params.data, true);

                return can.ajax(can.extend({
                            type: type || 'post',
                            dataType: dataType || 'json',
                            success: success,
                            error: error
                        }, params));
            }
59191
def as_json(*args)
      request = construct_request_hash
      request[:context] = s(context)
      request[:local_variables] = local_variables if local_variables

      {
        api_key: s(api_key),
        notifier: NOTIFIER,
        error: {
          token: id,
          class: s(error_class),
          message: s(error_message),
          backtrace: s(parse_backtrace(backtrace)),
          fingerprint: fingerprint_hash,
          tags: s(tags),
          causes: s(causes)
        },
        request: request,
        server: {
          project_root: s(config[:root]),
          revision: s(config[:revision]),
          environment_name: s(config[:env]),
          hostname: s(config[:hostname]),
          stats: stats,
          time: now,
          pid: pid
        }
      }
    end
1374223
function (req, res, options) {
    if (!options) {
      options = {};
    }
    options.operation = 'AGGREGATE';
    options.res = res;
    exports.aggregate.before(req, res, options);
    vulpejs.models.aggregate({
      model: req.params.model,
      aggregate: req.params.aggregate,
      callback: {
        success: function (results) {
          if (options && options.callback) {
            vulpejs.utils.execute(options.callback, results);
          } else {
            exports.aggregate.after(req, res, results);
            res.json({
              items: results,
            });
          }
        },
        error: function (error) {
          vulpejs.log.error('AGGREGATE', error);
          res.status(500).end();
        },
      },
    });
  }
1011039
function (req, res) {
        {modelName}.find(function (err, {pluralName}) {
            if (err) {
                return res.status(500).json({
                    message: 'Error when getting {name}.',
                    error: err
                });
            }
            return res.json({pluralName});
        });
    }
197957
function Args() {
    if (argv._.length >= 1) {
        try {
            // Attempt to parse 1st argument as JSON string
            _.extend(this, JSON.parse(argv._[0]));
        } catch (err) {
            // Pass, we must be in the console so don't worry about it
        }
    }
}
24841
def respond_with_json(object, options = {})
      respond_to do |format|
        format.json do
          render options.merge(json: object)
        end
      end
    end
33046
def as_json(_options = {})
      {
        resource_owner_id: resource_owner_id,
        scope: scopes,
        expires_in: expires_in_seconds,
        application: { uid: application.try(:uid) },
        created_at: created_at.to_i,
      }
    end