Skip to content

Commit d640dc7

Browse files
authored
handle empty dict (#375)
1 parent 43c90c0 commit d640dc7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

python/src/sbc_common_components/utils/camel_case_response.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ def camelcase(string):
4141

4242
def camelcase_dict(data, camel_dict: Dict[str, any]):
4343
"""Iterate through the dict and convert to camel case."""
44-
if data:
45-
# Handle the scenario where we aren't a dict
46-
if isinstance(data, list):
47-
return [camelcase_dict(item, {}) for item in data]
44+
45+
if isinstance(data, list):
46+
if not data: # empty array is falsy
47+
return []
48+
return [camelcase_dict(item, {}) for item in data]
49+
50+
if isinstance(data, dict):
51+
if not data: # empty dict is falsy
52+
return {}
53+
4854
for key, value in data.items():
4955
key = camelcase(key)
5056
if isinstance(value, dict):

0 commit comments

Comments
 (0)