An utility method to prepare a JSON result string, usable by the
    SignalReceiver

    :param code: A HTTP Code
    :param message: An associated message
350905
def _make_json_result(code, message="", results=None):
    
    return code, json.dumps({'code': code,
                             'message': message,
                             'results': results})
150164
function (method, result) {

      // result should not be undefined
      if (result === undefined) {
        console.warn('JSON-RPC2 response from method ' + methodName + ' should return a result. (JSON-RPC2 spec)')
        result = ''
      }

      var rpcMessage = {
        jsonrpc: '2.0',
        result: result,
        id: id
      }

      callback(rpcMessage)
      responseHasBeenSent = true

    }
333789
def jsonify(self,
                data: Any,
                code: Union[int, Tuple[int, str, str]] = HTTPStatus.OK,
                headers: Optional[Dict[str, str]] = None,
                ):
        
        return jsonify(data), code, headers or {}
760696
def error_response(message, status=400, code=None):
    """""""
    from django.http import JsonResponse
    data = {'message': message}
    if code:
        data['code'] = code
    LOG.error("Error response, status code is : {} | {}".format(status, data))
    return JsonResponse(data=data, status=status)
398820
def json_error_response(error, response, status_code=400):
    
    msg = {"error": error.error, "error_description": error.explanation}

    response.status_code = status_code
    response.add_header("Content-Type", "application/json")
    response.body = json.dumps(msg)

    return response
178286
def prepare_message(self, message_data, delivery_mode, priority=None,
            content_type=None, content_encoding=None):
        """"""
        properties = pika.BasicProperties(priority=priority,
                                          content_type=content_type,
                                          content_encoding=content_encoding,
                                          delivery_mode=delivery_mode)
        return message_data, properties
1158419
function sendResponse(code, message, statusCode) {
    /*jshint validthis:true*/
    var res = this;
    var data;
    var result;

    if (!res) {
      throw new Error('You called `error()`, detatched send from the response object');
    }

    code = code || 'UKN';
    message = message || (errors[code] && errors[code].message) || 'Unknown error occurred';
    statusCode = statusCode || (errors[code] && errors[code].statusCode) || '200';
    data = { code: code, message: message };

    res.setHeader('Content-Type', 'application/json');
    //res.statusCode = statusCode;
    if (code && 'object' === typeof code) {
      if (code.error) {
        code = code.error;
      }
      if (/message/.test(JSON.stringify(code))) {
        // '{}' !== JSON.stringify(code)
        data = code;
      } else {
        data = { type: code.type, name: code.name, message: code.message || code.toString() };
      }
    }

    result = JSON.stringify({ error: data }, null, '  ');
    res.end(result);
  }
1211862
def _StructMessageToJsonObject(self, message):
    """"""
    fields = message.fields
    ret = {}
    for key in fields:
      ret[key] = self._ValueMessageToJsonObject(fields[key])
    return ret
709272
def send_error_json(self, code, message, headers=None):
        ""
        if headers is None:
            headers = {}

        self.end_response(HttpResponseJson(code,
                                           {'code':    code,
                                            'message': message},
                                           headers))
655307
def sendMessage(self, to, message, extra={}):
        
        to = to if isinstance(to, list) else [to]
        to = [str(num) for num in to]
        data = {'to': to, 'text': message}
        data = self.merge(data, {'callback': 7, 'mo': 1}, extra)

        content = self.parseRest(self.request('rest/message', data, {}, 'POST'));
        result = []

        # Messages in the REST response will contain errors on the message entry itself.
        for entry in content['message']:
            entry = self.merge({'apiMessageId': False, 'to': data['to'][0], 'error': False, 'errorCode': False}, entry)
            result.append({
                'id': entry['apiMessageId'].encode('utf-8'),
                'destination': entry['to'].encode('utf-8'),
                'error': entry['error']['description'].encode('utf-8') if entry['error'] != False else False,
                'errorCode': entry['error']['code'].encode('utf-8') if entry['error'] != False else False
            });

        return result
1320332
def json_error_handler(exception):
    
    http_exception = isinstance(exception, exceptions.HTTPException)
    code = exception.code if http_exception else 500

    # log exceptions only (app debug should be off)
    if code == 500:
        current_app.logger.error(exception)

    response = jsonify(dict(message=str(exception)))
    response.status_code = code
    return response
984853
function (message, encoding) {
    return module.exports.jsonToObject(
      module.exports.decodePayload(message, encoding))
  }
1084416
def json_error(code, message):
    """"""
    # Message can be an unserializable object.
    message = repr(message)
    return jsonify(dict(request=request.path, message=message)), code
617048
public static JSONObject processResponse(int responseCode, String errorCode, String errorMsg) throws JSONException {
        JSONObject response = new JSONObject();
        response.put("responseCode", responseCode);
        response.put("errorCode", errorCode);
        response.put("errorMsg", errorMsg);

        return response;
    }
285475
@Override
  public void onMessage(WebSocket webSocket, String message) {
    JsonObject json = new JsonParser().parse(message).getAsJsonObject();
    if (json.has(ERROR)) {
      String error = json.get(ERROR).getAsString();
      callback.onError(new RuntimeException(error));

    } else if (json.has(WARNINGS)) {
      String warning = json.get(WARNINGS).getAsString();
      callback.onWarning(new RuntimeException(warning));
    } else if (json.has(BINARY_STREAMS)) {
      String contentType = json.get(BINARY_STREAMS)
          .getAsJsonArray()
          .get(0)
          .getAsJsonObject()
          .get(CONTENT_TYPE)
          .getAsString();
      callback.onContentType(contentType);
    } else if (json.has(WORDS)) {
      callback.onTimings(GSON.fromJson(message, Timings.class));
    } else if (json.has(MARKS)) {
      callback.onMarks(GSON.fromJson(message, Marks.class));
    }
  }
1232038
public static Result success(int code, String message) {
        return new Result(true, String.valueOf(code), message);
    }
268325
function responseJSON(success, message, result = null, code) {
    return {
        success,
        message,
        result,
        code,
        time: new Date()
    }
}