Skip to content
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

Option to autoconvert camelCase to snake_case #66

Closed
kiddten opened this issue Nov 17, 2019 · 3 comments
Closed

Option to autoconvert camelCase to snake_case #66

kiddten opened this issue Nov 17, 2019 · 3 comments

Comments

@kiddten
Copy link

kiddten commented Nov 17, 2019

Is it possible to add such option to Config?
I have some 3rd party json with keys in camelCase but that isn't appropriate naming for attributes in dataclass

@mjuraj
Copy link

mjuraj commented Nov 20, 2019

Not only that, it would be awesome to support removing trailing spaces from keys (e.g. my key is called from so I want to map it to from_

@konradhalas
Copy link
Owner

Hi @kiddick - thank you very much for reporting issue.

Unfortunately, I don't think it's a good idea to add any "data" processing features into dacite. I want to keep it simple.

I'm pretty sure that there are plenty of "camelCase-to-snake_case" libs in PyPI. You just have to call such lib before passing data to dacite.

@shaunc
Copy link

shaunc commented Sep 16, 2020

@konradhalas -- thanks so much for this library! I am trying to use it to convert a large structure loaded from yaml. As you note, converting individual strings is not a problem. However, walking the data structure and recursively converting them before passing the structure to dacite seems like duplicate work.

Perhaps you could consider a convert_keys option, that took a function to pre-process keys as they were encountered during conversion. That way, I could pass my favorite "camelCase-to-snake_case" function (or for that matter, "arbitrary string to snake case slug" function) without you having to wade into "processing data". (?) Happy to create a separate feature request if this seems more doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants