bswck / configzen

Manage configuration with pydantic.

Home Page:https://bswck.github.io/configzen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Translate camelCase to snake_case

ZeroIntensity opened this issue · comments

Use case

JSON keys tend to be in camelCase, as it originates from JavaScript, while Python attributes are expected to be in snake_case, per PEP 8. It would be nice for configzen to translate keys in camelCase in a JSON file to their corresponding snake_case attributes.

Example usage

{
    "fooBar": "hello world"
}
from configzen import ConfigModel

class Something(ConfigModel):
    foo_bar: str

conf = Something.load("something.json")
print(conf.foo_bar)  # hello world

Additional context

No response

Thanks for a valuable suggestion. I guess a good solution would be creating a key transformer. As for the new version of configzen, it could be possible with a serialization_alias (camel case) different than the field name (snake case).