data = { "user": { "profile": { "name": "Alice", "age": 30 }, "settings": { "theme": "dark" } }, "product": { "id": 123 } } # Safely get a nested value that might exist user_name = data.get("user", {}).get("profile", {}).get("name") # print(user_name) # Output: Alice # Safely get a nested value that might not exist, providing a default non_existent_field = data.get("user", {}).get("preferences", {}).get("language", "en") # print(non_existent_field) # Output: en # Without safe access, this would raise KeyError if 'preferences' didn't exist # user_language_unsafe = data["user"]["preferences"]["language"] # print(user_language_unsafe) # Raises KeyError