@@ -55,6 +55,46 @@ def convert_dict_keys_to_camel_case(data: dict[str, Any]) -> dict[str, Any]:
55
55
return result
56
56
57
57
58
+ def camel_to_snake (camel_str : str ) -> str :
59
+ """
60
+ Convert a camelCase or PascalCase string to snake_case.
61
+
62
+ Args:
63
+ camel_str: The camelCase/PascalCase string to convert
64
+
65
+ Returns:
66
+ The converted snake_case string
67
+ """
68
+ result_chars = []
69
+ for index , char in enumerate (camel_str ):
70
+ if char .isupper () and index != 0 and (not camel_str [index - 1 ].isupper ()):
71
+ result_chars .append ("_" )
72
+ result_chars .append (char .lower ())
73
+ return "" .join (result_chars )
74
+
75
+
76
+ def convert_dict_keys_to_snake_case (data : Any ) -> Any :
77
+ """
78
+ Convert all dictionary keys from camelCase/PascalCase to snake_case.
79
+ Works recursively for nested dictionaries and lists. Non-dict/list inputs are returned as-is.
80
+
81
+ Args:
82
+ data: Potentially nested structure with dictionaries/lists
83
+
84
+ Returns:
85
+ A new structure with all dict keys converted to snake_case
86
+ """
87
+ if isinstance (data , dict ):
88
+ converted : dict [str , Any ] = {}
89
+ for key , value in data .items ():
90
+ converted_key = camel_to_snake (key ) if isinstance (key , str ) else key
91
+ converted [converted_key ] = convert_dict_keys_to_snake_case (value )
92
+ return converted
93
+ if isinstance (data , list ):
94
+ return [convert_dict_keys_to_snake_case (item ) for item in data ]
95
+ return data
96
+
97
+
58
98
def format_simplified_tree (node : AccessibilityNode , level : int = 0 ) -> str :
59
99
"""Formats a node and its children into a simplified string representation."""
60
100
indent = " " * level
0 commit comments