0

I have a class

class SampleModel(BaseModel):
    first_name: str
    last_name int

When I export it to json, I want to json to be

{
    "first-name": "john doe",
    "last-name": 1234
}

I was going to use aliases, but does pydantic have a config or an option to directly do this for all fields in a model?

wovano
  • 4,543
  • 5
  • 22
  • 49
BBloggsbott
  • 195
  • 2
  • 12
  • Does this answer your question? [Is it possible to change the output alias in pydantic?](https://stackoverflow.com/questions/69306103/is-it-possible-to-change-the-output-alias-in-pydantic) – JacekK Sep 27 '22 at 19:52
  • The approach I was looking for was to use Alias Generators. – BBloggsbott Sep 28 '22 at 11:14

1 Answers1

0

Pydantic has an Alias Generator which can be used.

BBloggsbott
  • 195
  • 2
  • 12