Creates the response JSON body
8482
public function createBody()
    {
        $body = array(
            'isDestructive' => $this->removesRows,
            'isError' => $this->isError(),
            'isWarning' => false,
            'message' => $this->message,
            'successClasses' => $this->successClasses,
            'failedClasses' => $this->failedClasses
        );

        if (!$this->isError()) {
            $body['records'] = array(
                'success' => array(),
                'failed' => array()
            );

            foreach ($this->successRecords as $record) {
                $data = array('id' => $record->ID, 'class' => $record->ClassName);
                if (!$this->removesRows) {
                    $data['row'] = $this->getRecordGridfieldRow($record);
                }
                $body['records']['success'][] = $data;
            }

            $body['records']['failed'] = $this->failedRecords;
        }

        if (count($body['records']['success']) === 0) {
            $body['isWarning'] = true;
        }

        $this->body = Convert::raw2json($body);
    }
444429
def make_response(message, status_code, details=None):
    """"""
    response_body = dict(message=message)
    if details:
        response_body['details'] = details
    response = jsonify(response_body)
    response.status_code = status_code
    return response
177675
def response_builder(self, response):
        '''
        '''
        try:
            r = response.json()
            result = r['query']['results']
            response = {
                'num_result': r['query']['count'] ,
                'result': result
            }
        except (Exception,) as e:
            print(e)
            return response.content

        return response
59900
private function interpretResponseJSON()
    {
        $this->debug_echo("\n\nResponse (json):\n");
        $this->debug_print_r($this->state['response']['body_raw']);

        // Convert response from json to array format if required
        if ($this->config['dataFormat'] == 'array') {
            try {
                $this->state['response']['body'] = json_decode(
                    $this->state['response']['body_raw'],
                    true
                ); 
            } catch (Exception $e) {
                $msg = 'Invalid response body from API: '.$this->state['response']['body_raw']
                     . '(HTTP response code was '.$this->state['response']['code'].')';
                throw new ApiException($msg, $this->state);
            }
            $this->debug_echo("\n\nResponse (array):\n"); 
            $this->debug_print_r($this->state['response']['body']); 
        } else {
            $this->state['response']['body'] = $this->state['response']['body_raw'];
        }

        if ($this->state['response']['code'] < 200 ||
            $this->state['response']['code'] >= 300
        ) {
            $this->handleHttpError();
        }

        return $this->state;
    }
1373438
def create_response(request, body=None, status=None, headers=None):
    # type: (BaseHttpRequest, Any, HTTPStatus, dict) -> HttpResponse
    
    if body is None:
        return HttpResponse(None, status or HTTPStatus.NO_CONTENT, headers)
    else:
        body = request.response_codec.dumps(body)
        response = HttpResponse(body, status or HTTPStatus.OK, headers)
        response.set_content_type(request.response_codec.CONTENT_TYPE)
        return response
211194
def _create_json(self):
        
        data_json = {
            "name": self.name,
            "description": self.description,
            "autoJoin": self.autoJoin,
            "realm": self.realm,
        }
        return data_json
1216363
def make_request_body(opts, headers)
      case
      when opts.body
        opts.body
      when opts.form
        form = HTTP::FormData.create opts.form
        headers[Headers::CONTENT_TYPE] ||= form.content_type
        form
      when opts.json
        body = MimeType[:json].encode opts.json
        headers[Headers::CONTENT_TYPE] ||= "application/json; charset=#{body.encoding.name}"
        body
      end
    end
416915
def _create_json(self):
        
        data_json = {
            "name": self.name,
            "includesPattern": self.includesPattern,
            "excludesPattern": self.excludesPattern,
            "repositories": self._repositories,
            "principals": {
                'users': self._users,
                'groups': self._groups,
            }
        }
        return data_json
427102
public function makeJsonReponse($status_code, $body)
    {
        $this->getResponse()->setBody(json_encode($body, JSON_UNESCAPED_SLASHES));
        $this->getResponse()->setStatusCode($status_code);
        $this->getResponse()->addHeader("Content-type", "application/json");

        return $this->getResponse();
    }
199004
def json(
    body,
    status=200,
    headers=None,
    content_type="application/json",
    dumps=json_dumps,
    **kwargs
):
    
    return HTTPResponse(
        dumps(body, **kwargs),
        headers=headers,
        status=status,
        content_type=content_type,
    )
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
132136
def _json_to_subscriptions(response_body):
    
    data = json.loads(response_body)
    subscriptions = []
    for subscription_data in data.get("subscriptionList", []):
        subscriptions.append(Subscription().from_json(
            data.get('uwNetID'), subscription_data))

    return subscriptions
1314954
def decode_json_body():
    
    raw_data = request.body.read()

    try:
        return json.loads(raw_data)
    except ValueError as e:
        raise HTTPError(400, e.__str__())
707912
def json_response(data, status=200, serializer=None):
    
    return HttpResponse(json.dumps(data, default=serializer),
                        status=status,
                        content_type='application/json; charset=UTF-8')
555424
def render_to_json(response, request=None, **kwargs):
    
    # determine the status code
    if hasattr(response, 'status_code'):
        status_code = response.status_code
    elif issubclass(type(response), Http404):
        status_code = 404
    elif issubclass(type(response), Exception):
        status_code = 500
        logger.exception(str(response), extra={'request': request})
        
        if settings.DEBUG:
            import sys
            reporter = ExceptionReporter(None, *sys.exc_info())
            text = reporter.get_traceback_text()
            response = HttpResponseServerError(text, content_type='text/plain')
        else:
            response = HttpResponseServerError("An error occured while processing an AJAX request.", content_type='text/plain')
    else:
        status_code = 200

    # creating main structure
    data = {
        'status': status_code,
        'statusText': REASON_PHRASES.get(status_code, 'UNKNOWN STATUS CODE'),
        'content': response
    }

    return JSONResponse(data, **kwargs)
747188
def _json_to_supported(response_body):
    
    data = json.loads(response_body)
    supported = []
    for supported_data in data.get("supportedList", []):
        supported.append(Supported().from_json(
            supported_data))

    return supported
1062693
def create(self, data):
        
        response = self.http.post(str(self), json=data, auth=self.auth)
        response.raise_for_status()
        return response.json()