Add PydanticJSONResponse by eltoder · Pull Request #14299 · fastapi/fastapi
When using this response class, json serialization is done using Pydantic's built-in json serialization (`dump_json(r)`) instead of generating an intermediate dict that is later serialized using a json library (`json.dumps(dump_python(r))`). In my testing this is 3-4x faster than using the standard json library (the default) and 50% faster than using orjson, without requiring any extra dependencies. This also allows configuring serialization behavior per model using Pydantic's model_config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters