-
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
Dashes removed by camelize #151
Comments
I had this issue today too, but the value of the dictionary key was replaced. It shouldn't be the case looking at the tests Line 102 in f0e3fe0
|
…ys and dashed values
okay sorry, that was my mistake :) @alexandersoto are you using pydantic or something? I was trying to camelize JSON string instead of a dictionary and it removed dashes and even spaces. I wrote a test: For keys or strings like in your example - dashes, underscores, and spaces should be reduced - that's something I'd expect at least |
Pydantic's Object.model_dump_json() in combination with humps.camelize() produces some unexpected results. I have a pydantic object, which contains properties with UUID-values. When serializing to JSON-string using the Object.model_dump_json() method of pydantic, the values are correctly serialized, but all keys in the JSON-string appears "decamelized". As I wanted the keys output in the JSON-string to be "camelized", I wrapped the method-call inside the humps.camelize() method:
The PydanticObject is serialized to a JSON-string, but the UUID-values appears without "hyphens". E.g. the UUID-value There seems to be a bug in the humps.camelize() method that causes this. |
@jonasao, I've also encountered this issue. However, the problem doesn't lie with pyhumps. The issue arises because model_dump_json returns a string, and camelize processes strings differently than dictionaries (obviously :D). You should probably use it like this: |
Describe the bug
Dashes are replaced and treated as underscores. Is this intentional? It seems to be based on:
humps/humps/main.py
Line 27 in 2bbaf1e
My use case is to convert dictionaries with snake case variables to camel case (python code to a JS client). The dictionaries sometimes contain uuids as keys which contain dashes. Those should not be modified. Is there a way to support this use case?
To Reproduce
humps.camelize("9e3f4a89-9989-4190-89a0-f50ffa3826db") => "9e3f4a899989419089a0F50ffa3826db"
Expected behavior
humps.camelize("9e3f4a89-9989-4190-89a0-f50ffa3826db") => "9e3f4a89-9989-4190-89a0-f50ffa3826db"
The text was updated successfully, but these errors were encountered: