-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"
}
1
  • Do this and this answer your question? Commented Sep 4, 2023 at 4:09

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.