The authors of orjson describe it like this:
orjson is a fast, correct JSON library for Python. It benchmarks as the fastest Python library for JSON and is more correct than the standard json library or other third-party libraries.
Based on the benchmarks the authors have shared, orjson is 5 to 50 times faster than the standard json library.
Add an option to use orjson instead of json.
json is the only option for JSON serialization.
Comparing the standard Jsonifier used by Connexion and orjson in an example API call in my application, I see the difference in performance can be extreme, 570 times faster:
FlaskApi._serialize_data():
# 2434078 bytes, total time 8ms
body = orjson.dumps(data, option=orjson.OPT_NAIVE_UTC | orjson.OPT_NON_STR_KEYS)
# 3899087 bytes, total time 4565ms
body = cls.jsonifier.dumps(data)
To validate the output, I used json.loads() and verified that it creates identical objects. It does.
Most helpful comment
Comparing the standard Jsonifier used by Connexion and orjson in an example API call in my application, I see the difference in performance can be extreme, 570 times faster:
FlaskApi._serialize_data():
To validate the output, I used
json.loads()and verified that it creates identical objects. It does.