-
Notifications
You must be signed in to change notification settings - Fork 33
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
camelizeKeys only rather than the full dictionary (values and keys) #294
Comments
@robinwkurtz Hi, thanks for opening the issue. Sorry, but I couldn't replicate the problem. It'd be nice if you could list some use cases. I did this: >>> d = {"s_gv": "j_db", "ir_o": "op_m"}
>>> humps.camelize(d)
{'sGv': 'j_db', 'irO': 'op_m'}
However, it's worth noting that if the values include a mapping, it will convert their keys as well: >>> d = {"s_gv": "j_db", "sub_dict": {"ir_o": "op_m"}}
>>> humps.camelize(d)
{'sGv': 'j_db', 'subDict': {'irO': 'op_m'}} Currently, there's no way to limit this behaviour but there's an old issue requesting a similar functionality here: #233 |
Thanks for the comment @ificiana, my issue was in fact json.dumps which I was using within the camilize function. >>> d = {"s_gv": "j_db", "ir_o": "op_m"}
>>> print('plain', d)
plain {'s_gv': 'j_db', 'ir_o': 'op_m'}
>>> print('humps', humps.camelize(d))
humps {'sGv': 'j_db', 'irO': 'op_m'}
>>> print('json', json.dumps(d))
json {"s_gv": "j_db", "ir_o": "op_m"}
>>> print('humps.json', humps.camelize(json.dumps(d)))
humps.json {"sGv":"jDb","irO":"opM"}
>>> print('json.humps', json.dumps(humps.camelize(d)))
json.humps {"sGv": "j_db", "irO": "op_m"} I'm trying to camelize the keys of a large dataclass before sending it through a request, and I guess the combination of the two do not work well together. The solution in my case (in the chance that someone else is doing the same), is to wrap my dataclass in an
Sorry for the issue! |
Right! I see, no problem. |
Is your feature request related to a problem? Please describe.
It would be nice to have the ability to only camelize a dictionary's keys, rather than all of the values as wwell.
Describe the solution you'd like
https://github.com/domchristie/humps#humpscamelizekeysobject-options -- Converts object keys to camelCase. It also converts arrays of objects.
Describe alternatives you've considered
Looping over the dictionary myself and using
humps.camelize
on keys onlyAdditional context
Thanks for the great tool!
The text was updated successfully, but these errors were encountered: