I have the following transform script but it's only replacing spaces with underscores at the top level of the object structure and not any of the sub-levels.
def transform(self, value, quality, timestamp):
# Create a new dictionary to store the transformed keys
transformed_value = {}
# Define a helper function to recursively transform the keys
def transform_keys(dictionary):
# Iterate through each key-value pair in the dictionary
for key, val in dictionary.items():
# Replace spaces with underscores in the key
new_key = key.replace(" ", "_")
# Check if the value is a dictionary
if isinstance(val, dict):
# Recursively transform the sub-dictionary
transformed_value[new_key] = transform_keys(val)
else:
# Add the new key and corresponding value to the transformed dictionary
transformed_value[new_key] = val
# Call the helper function to transform the keys
transform_keys(value)
# Return the transformed dictionary
return transformed_value
Any thoughts on what the issue is or how to modify this to evaluate correctly through all the sub-levels and replace spaces with underscores?