I have JSON with params from DB:
{
"model": "Example",
"weight": "1"
}
I need to change "model" key in output JSON with pydantic (set it custom name)
{
"changed_key": "Example",
"weight": "1"
}
I have JSON with params from DB:
{
"model": "Example",
"weight": "1"
}
I need to change "model" key in output JSON with pydantic (set it custom name)
{
"changed_key": "Example",
"weight": "1"
}
You should use serialization_alias
parameter
from pydantic import BaseModel, Field
class Model(BaseModel):
model: str = Field(..., serialization_alias='changed_key')
weight: str
Docs: https://docs.pydantic.dev/latest/usage/fields/#field-aliases