Merge pull request #15200 from wimnat/feature/handle_lists_in_snake_dict_creation
Handle lists during dict recursion
This commit is contained in:
commit
e1461ef792
1 changed files with 19 additions and 2 deletions
|
@ -276,11 +276,28 @@ def camel_dict_to_snake_dict(camel_dict):
|
||||||
return all_cap_re.sub(r'\1_\2', s1).lower()
|
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 = {}
|
snake_dict = {}
|
||||||
for k, v in camel_dict.iteritems():
|
for k, v in camel_dict.iteritems():
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
v = camel_dict_to_snake_dict(v)
|
snake_dict[camel_to_snake(k)] = camel_dict_to_snake_dict(v)
|
||||||
snake_dict[camel_to_snake(k)] = 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
|
return snake_dict
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue