def get_json_request(self):
        """
        friendly method to parse a proper json request (i.e.: **application/json** or **text/json**)
        :returns: a dict with the parsed data, unless the request data does not contain a valid json string or the content-type do not portray a json request.
        """
        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
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
friendly method to parse a proper json request (i.e.: **application/json** or **text/json**)
        :returns: a dict with the parsed data, unless the request data does not contain a valid json string or the content-type do not portray a json request.