Excluding None (optional fields) from json response bodies #3072
-
Many of our pydantic models have optional fields ( When doing this with pydantic natively, I can just pass Is there any way to exclude optional fields from the serialized json response? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
On a related note, I have a similar concern regarding excluding default values ( I simply cannot see how to customize the serialization of the pydantic models (other than develop some kind of plugin I suppose, but that seems very complicated). |
Beta Was this translation helpful? Give feedback.
-
Is |
Beta Was this translation helpful? Give feedback.
That's the best way to do this for Pydantic, yes.