1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #15200 from wimnat/feature/handle_lists_in_snake_dict_creation

Handle lists during dict recursion
This commit is contained in:
Brian Coca 2016-03-31 06:25:11 -07:00
commit e1461ef792

View file

@ -276,11 +276,28 @@ def camel_dict_to_snake_dict(camel_dict):
return all_cap_re.sub(r'\1_\2', s1).lower()
def value_is_list(camel_list):
checked_list = []
for item in camel_list:
if isinstance(item, dict):
checked_list.append(camel_dict_to_snake_dict(item))
elif isinstance(item, list):
checked_list.append(value_is_list(item))
else:
checked_list.append(item)
return checked_list
snake_dict = {}
for k, v in camel_dict.iteritems():
if isinstance(v, dict):
v = camel_dict_to_snake_dict(v)
snake_dict[camel_to_snake(k)] = v
snake_dict[camel_to_snake(k)] = camel_dict_to_snake_dict(v)
elif isinstance(v, list):
snake_dict[camel_to_snake(k)] = value_is_list(v)
else:
snake_dict[camel_to_snake(k)] = v
return snake_dict