pydantic convert to jsonable dict (not full json string)
Pydantic 1.x (old answer) The current version of pydantic does not support creating jsonable dict straightforwardly. But you can use the following trick: Note: This is a suboptimal solution class Model(BaseModel): the_id: UUID = Field(default_factory=uuid4) print(json.loads(Model().json())) {‘the_id’: ‘4c94e7bc-78fe-48ea-8c3b-83c180437774’} Or more efficiently by means of orjson orjson.loads(Model().json()) Pydantic 2 There is model_dump() method accepting mode parameter. … Read more