Returns a JSON response containing 'context' as payload
975154
def render_to_response(self, context, indent=None):
        ""
        return self.get_json_response(self.convert_context_to_json(context, indent=indent))
20816
def __json_hooks(json_object):
        
        json_object = Mastodon.__json_strnum_to_bignum(json_object)        
        json_object = Mastodon.__json_date_parse(json_object)
        json_object = Mastodon.__json_truefalse_parse(json_object)
        json_object = Mastodon.__json_allow_dict_attrs(json_object)
        return json_object
1165341
def render_to_response(self, context, **response_kwargs):
        
        # should we actually render in json?
        if '_format' in self.request.GET and self.request.GET['_format'] == 'json':
            return JsonResponse(self.as_json(context), safe=False)

        # otherwise, return normally
        else:
            return super(SmartView, self).render_to_response(context)
924130
def json(self, **kwargs):
        '''
        
        '''
        body = self._decompress(self.encoding)
        return _json.loads(body, **kwargs)
775885
def get_context_data(self, **kwargs):
        """"""
        context = super().get_context_data(**kwargs)
        context.update({
            'title': self.get_title(),
            'ajax_url': self.get_ajax_url(),
            'download_url': self.get_download_url(),
            'create_url': self.get_create_url(),
        })
        return context
28088
private String patchedJsonBody(ActionContext context) {
        String body = context.body();
        if (S.blank(body)) {
            return body;
        }
        if (context.xmlEncoded()) {
            Document doc = XML.read(body);
            JSONObject json = $.convert(doc).to(JSONObject.class);
            body = JSON.toJSONString(json.containsKey(xmlRootTag) ? json.get(xmlRootTag) : json);
        }
        if (1 < fieldsAndParamsCount(context)) {
            return body;
        }
        String theName = singleJsonFieldName(context);
        if (null == theName) {
            return body;
        }
        int theNameLen = theName.length();
        body = body.trim();
        boolean needPatch = body.charAt(0) == '[';
        if (!needPatch) {
            if (body.charAt(0) != '{') {
                throw new IllegalArgumentException("Cannot parse JSON string: " + body);
            }
            boolean startCheckName = false;
            int nameStart = -1;
            for (int i = 1; i < body.length(); ++i) {
                char c = body.charAt(i);
                if (c == ' ') {
                    continue;
                }
                if (startCheckName) {
                    if (c == '"') {
                        break;
                    }
                    int id = i - nameStart - 1;
                    if (id >= theNameLen || theName.charAt(i - nameStart - 1) != c) {
                        needPatch = true;
                        break;
                    }
                } else if (c == '"') {
                    startCheckName = true;
                    nameStart = i;
                }
            }
        }
        return needPatch ? S.fmt("{\"%s\": %s}", theName, body) : body;
    }
180721
def get_json(environ):
    '''
    
    '''
    content_type = environ.get('CONTENT_TYPE', '')
    if content_type != 'application/json':
        raise HTTPError(406, 'JSON required')

    try:
        return salt.utils.json.loads(read_body(environ))
    except ValueError as exc:
        raise HTTPError(400, exc)
557864
def json_response(func):
    

    @wraps(func)
    def wrapper(request, *args, **kwargs):
        res = func(request, *args, **kwargs)
        request.setHeader('Content-Type', 'application/json')
        return json.dumps(res)

    return wrapper
1208571
def get_context_json(self, context):
        '''
        
        '''
        # Initialize answer
        answer = {}

        # Metadata builder
        answer['meta'] = self.__jcontext_metadata(context)

        # Filter builder
        answer['filter'] = self.__jcontext_filter(context)

        # Head builder
        answer['table'] = {}
        answer['table']['head'] = self.__jcontext_tablehead(context)
        answer['table']['body'] = None
        answer['table']['header'] = None
        answer['table']['summary'] = None

        # Return answer
        return answer
437914
def as_json(context):
    """"""
    info = {
        'info': cgi.escape(pprint.pformat(context.context)),
    }
    return Response(content_type='application/json', body=json.dumps(info))
866729
function requestToContext(req) {
  const queryMap = req.method === 'POST' ? req.body : _url2.default.parse(req.url, true).query;
  const context = {};

  if (queryMap) {
    Object.keys(queryMap).forEach(key => {
      let arg = queryMap[key];

      if (parseArgs[key] && arg) {
        context[key] = JSON.parse(arg);
      } else {
        context[key] = arg;
      }
    });
  }
  return Object.freeze(context);
}
1172814
def getJson(cls, url, method='GET', headers={}, data=None, socket=None, timeout=120):
        
        if not 'Content-Type' in headers:
            headers['Content-Type'] = ['application/json']

        body = yield cls().getBody(url, method, headers, data, socket, timeout)

        defer.returnValue(json.loads(body))
607241
def resp_json(resp):
    
    if isinstance(resp, flask.Response):
        if 400 <= resp.status_code < 600:
            msg = resp.status
            try:
                result = loads(resp.data.decode("utf-8"))
                if isinstance(result, str):
                    msg = "%s, %s" % (resp.status, result)
                else:
                    msg = "%s %s, %s" % (
                        resp.status_code, result["error"], result["message"])
            except Exception:
                pass
            raise requests.HTTPError(msg, response=resp)
        else:
            return loads(resp.data.decode("utf-8"))
    else:
        try:
            resp.raise_for_status()
        except requests.HTTPError as ex:
            # the response may contains {"error": "", "message": ""}
            # append error and message to exception if possible
            try:
                result = resp.json()
                ex.args += (result["error"], result["message"])
            except (ValueError, KeyError):
                pass
            raise
        return resp.json()
1153719
def to_dict(self):
        
        with self._lock:
            result = {}
            if self._gpayload:
                result.update(self._gpayload)
            if self._tpayload:
                result.update(getattr(self._tpayload, "context", {}))
            return result
172169
def json_exception(context, request):
    """"""
    request.response.status = context.code
    return {'error': context._status, 'messages': context.message}
292218
def render_to_response(self, context, **response_kwargs):
        
        response_kwargs['content_type'] = 'application/json'
        return self.response_class(
            self.convert_context_to_json(context),
            **response_kwargs
        )
884840
def get_response(self, **kwargs):
        
        return Response(
            json.dumps({"error": self.message}),  # pylint: disable=exception-message-attribute
            status_code=self.status_code,
            content_type="application/json",
            charset="utf-8",
            **kwargs
        )