New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pydantic base model to parse and return camelCase JSON #17
Comments
IrrerPolterer
changed the title
Pydantic base model to parse and dump camelCase JSON, but works with snake_case python code
Pydantic base model to parse and dump camelCase JSON
Feb 21, 2023
IrrerPolterer
changed the title
Pydantic base model to parse and dump camelCase JSON
Pydantic base model to parse and return camelCase JSON
Feb 21, 2023
Hey, That's the good one! We do the same within our projects 💯 I didn't include it in the list since not every project needs camelCase, but this issue could be a good reference for those who do 👍 |
the new version of Pydantic includes all of these built-in, no need to install humps anymore: from pydantic import BaseModel
from pydantic.alias_generators import to_camel
class BaseSchema(BaseModel):
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to be able to both...
For this I'm using a custom base model for pretty much all my Pydantic schemas:
(This requires the pyHumps package.)
With this BaseSchema, I can now create pydantic schemas with the intended behavior:
My solution above uses the
camelize
function from the pyhumps package. Alternatively, you can create the function yourself like this:The text was updated successfully, but these errors were encountered: