Parse JSON request, storing content in object attributes.

        Args:
            body: str. HTTP request body.

        Returns:
            self
558139
def parse(self, body):
        
        if isinstance(body, six.string_types):
            body = json.loads(body)

        # version
        version = body['version']
        self.version = version

        # session
        session = body['session']
        self.session.new = session['new']
        self.session.session_id = session['sessionId']
        application_id = session['application']['applicationId']
        self.session.application.application_id = application_id
        if 'attributes' in session and session['attributes']:
            self.session.attributes = session.get('attributes', {})
        else:
            self.session.attributes = {}
        self.session.user.user_id = session['user']['userId']
        self.session.user.access_token = session['user'].get('accessToken', 0)

        # request
        request = body['request']

        # launch request
        if request['type'] == 'LaunchRequest':
            self.request = LaunchRequest()

        # intent request
        elif request['type'] == 'IntentRequest':
            self.request = IntentRequest()
            self.request.intent = Intent()
            intent = request['intent']
            self.request.intent.name = intent['name']
            if 'slots' in intent and intent['slots']:
                for name, slot in six.iteritems(intent['slots']):
                    self.request.intent.slots[name] = Slot()
                    self.request.intent.slots[name].name = slot['name']
                    self.request.intent.slots[name].value = slot.get('value')

        # session ended request
        elif request['type'] == 'SessionEndedRequest':
            self.request = SessionEndedRequest()
            self.request.reason = request['reason']

        # common - keep after specific requests to prevent param overwrite
        self.request.type = request['type']
        self.request.request_id = request['requestId']
        self.request.timestamp = request['timestamp']

        return self
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,
    )
833210
def _prepare_body(self):
        
        content_type = self.__consume
        if not content_type:
            content_type = self.__op.consumes[0] if self.__op.consumes else 'application/json'
        if self.__op.consumes and content_type not in self.__op.consumes:
            raise errs.SchemaError('content type {0} does not present in {1}'.format(content_type, self.__op.consumes))

        # according to spec, payload should be one and only,
        # so we just return the first value in dict.
        for parameter in self.__op.parameters:
            parameter = final(parameter)
            if getattr(parameter, 'in') == 'body':
                schema = deref(parameter.schema)
                _type = schema.type
                _format = schema.format
                name = schema.name
                body = self.__p['body'][parameter.name]
                return content_type, self.__op._mime_codec.marshal(content_type, body, _type=_type, _format=_format, name=name)
        return None, None
776687
def json(self, data):
        """"""
        if data is not None:
            self._body = json.dumps(data)
            self.add_header('Content-Type', 'application/json')
1355789
def _process_req_body(self, body):
    
    try:
      return json.loads(body)
    except ValueError:
      return urlparse.parse_qs(body, keep_blank_values=True)
231747
def parse(body)
      body.is_a?(String) ? JSON.parse(body) : body
    rescue JSON::ParserError
      {}
    end
584861
def get_json_request(self):
        
        content_type = request.headers.get('Content-Type', 'text/plain')
        if content_type not in ('application/json', 'text/json'):
            self.log.error('get_json_request() called in a request that does not have a json content-type: %s. Refusing to parse the request data', content_type)
            return {}

        try:
            data = json.loads(request.data)
        except ValueError:
            self.log.exception(
                "Trying to parse json body in the %s to %s",
                request.method, request.url,
            )
            data = {}

        return data
366780
function parseBody(req) {
    return extractBody(req)
        .then(() => {
            if (req.body && typeof req.body === 'object') return req.body;
            try {
                return JSON.parse(req.body);
            } catch (err) {
                throw Error('Unexpected body format received. Expected application/json, received: ' + req.body);
            }
        });
}
294822
def getBody(self):
        
        data = None
        try:
            data = json.loads(self.request.body)
        except:
            data = json.loads(urllib.unquote_plus(self.request.body))
        return data
630509
def request(method, path, params=None, data=None, auto_retry=True):
    
    body = None
    if data is not None:
        body = json.dumps(data, cls=utils.DateTimeEncoder)

    headers = {
        'accept': 'application/json',
        'content-type': 'application/json',
        'user-agent': analyzere.user_agent,
    }
    resp = request_raw(method, path, params=params, body=body, headers=headers,
                       auto_retry=auto_retry)
    content = resp.text
    if content:
        try:
            content = json.loads(content, cls=utils.DateTimeDecoder)
        except ValueError:
            raise errors.ServerError('Unable to parse JSON response returned '
                                     'from server.', resp, resp.status_code)
    return content
119023
def _json_body_(cls):
        
        json = []
        for series_name, data in six.iteritems(cls._datapoints):
            for point in data:
                json_point = {
                    "measurement": series_name,
                    "fields": {},
                    "tags": {},
                    "time": getattr(point, "time")
                }

                for field in cls._fields:
                    value = getattr(point, field)
                    if value is not None:
                        json_point['fields'][field] = value

                for tag in cls._tags:
                    json_point['tags'][tag] = getattr(point, tag)

                json.append(json_point)
        return json
559160
def with_body(self, body):
        # @todo take encoding into account
        
        try:
            self.body = body.encode('utf-8')
        except:
            try:
                self.body = bytes(body)
            except:
                raise ValueError("Request body must be a string or bytes-like object.")
        hasher = hashlib.sha256()
        hasher.update(self.body)
        digest = base64.b64encode(hasher.digest()).decode('utf-8')
        self.with_header("X-Authorization-Content-Sha256", digest)
        return self
922728
def set_json_item(key, value):
    
    data = get_json()
    data[key] = value

    request = get_request()
    request["BODY"] = json.dumps(data)
281577
def _parse_top_level(self, body):
        

        link = 'jsonapi.org/format/#document-top-level'

        try:
            if not isinstance(body['data'], dict):
                raise TypeError
        except (KeyError, TypeError):
            self.fail('JSON API payloads MUST be a hash at the most '
                      'top-level; rooted at a key named `data` where the '
                      'value must be a hash. Currently, we only support '
                      'JSON API payloads that comply with the single '
                      'Resource Object section.', link)

        if 'errors' in body:
            self.fail('JSON API payloads MUST not have both `data` & '
                      '`errors` top-level keys.', link)
109525
def loadFromString(self, body):
        
        try:
            self._data = json.loads(body)
        except Exception as e:
            raise ConfigException('%s: invalid config body: %s' %
                                  (self._path, e.message))
        self._doDefaults()
1094066
def _json(self, response):
        
        if response.status_code == 204:
            return None
        try:
            return response.json()
        except ValueError as e:
            raise ValueError(
                'Exception: %s\n'
                'request: %s, response code: %s, response: %s' % (
                    str(e), response.request.url, response.status_code,
                    response.content,
                )
            )
1314649
def parse_request(self, request, parameters=None, fake_method=None):
        '''
        
        '''
        return (request.method,
                request.url,
                request.headers,
                request.form.copy())