import ujson
from flask.json.provider import JSONProvider
class UJSONProvider(JSONProvider):
# https://github.com/ultrajson/ultrajson
encode_html_chars = False
ensure_ascii = False
indent = 4
def dumps(self, obj, **kwargs):
option = {
"encode_html_chars": self.encode_html_chars,
"ensure_ascii": self.ensure_ascii,
"indent": self.indent
}
return ujson.dumps(obj, **option)
def loads(self, s, **kwargs):
return ujson.loads(s)
app = OpenAPI(__name__, info=info)
# use ujson
ujson_provider = UJSONProvider(app)
app.json = ujson_provider