Example #1
0
def jsonify(*args, **kwargs):
    status = 200
    if __debug__:
        _assert_have_json()
    if "status" in kwargs:
        status = kwargs.pop("status", 200)
    return current_app.response_class(
        json.dumps(dict(*args, **kwargs), indent=None if request.is_xhr else 2, cls=CustomEncoder),
        status=status,
        mimetype="application/json",
    )
Example #2
0
    def json(self):
        """If the mimetype is `application/json` or `application/json-rpc`
        this will contain the parsed JSON data.  Otherwise this will be `None`.

        This requires Python 2.6 or an installed version of simplejson.
        """
        if __debug__:
            _assert_have_json()
        if self.mimetype in ['application/json', 'application/json-rpc']:
            request_charset = self.mimetype_params.get('charset')
            try:
                if request_charset is not None:
                    return json.loads(self.data, encoding=request_charset)
                return json.loads(self.data)
            except ValueError as E:
                return self.on_json_loading_failed(E)
Example #3
0
    def json(self):
        """If the mimetype is `application/json` or `application/json-rpc`
        this will contain the parsed JSON data.  Otherwise this will be `None`.

        This requires Python 2.6 or an installed version of simplejson.
        """
        if __debug__:
            _assert_have_json()
        if self.mimetype in ["application/json", "application/json-rpc"]:
            request_charset = self.mimetype_params.get("charset")
            try:
                if request_charset is not None:
                    return json.loads(self.data, encoding=request_charset)
                return json.loads(self.data)
            except ValueError as E:
                return self.on_json_loading_failed(E)
Example #4
0
def mongo_jsonify(*args, **kwargs):
    if __debug__:
        _assert_have_json()
    return current_app.response_class(json.dumps(dict(*args, **kwargs),
        indent=None if request.is_xhr else 2, cls=MongoEngineEncoder), mimetype='application/json')