How about using deep_transform_keys here instead of doing recursion by yourself? See active support doc for more details