10-14-2024 07:47 AM
I have an array which look like this below. I can manage to remove the 1st level of fields using except formula.
users[0].except(:two_factor_auth_enabled,:signature).
I am trying to remove the nested object field using the below formula.
users[0].except(:two_factor_auth_enabled,:signature,:user_fields["city"]).
But it is not working as expected. Kindly give me the solution for this process.
"users": [
{
"id": 12345,
"name": "Abdul Khader Malim",
"email": "amalim@logitech.com",
"two_factor_auth_enabled": null,
"signature": "",
"user_fields": {
"address_line_1": "3221 COLEMAN AVE",
"address_line_2": null,
"birth_year": null,
"city": "OCEANSIDE",
"company_school": null,
"country": "country_nl",
"gender": null,
"newsletter_subscription": false,
"postal_code": "92054",
"region": null,
"school_district": null,
"site": null,
"state": "CA"
}
}
]
10-14-2024 10:05 AM
I can't find a way to target the nested array either. You might have to break it out separately and combine them. I'm interested to know if you find a more elegant solution.
10-14-2024 08:05 PM - edited 10-14-2024 08:06 PM
Dear, @amalim
In Workato, the except formula does not directly work on nested object like you have in the user_fields. When you're trying to remove fields from a nested object, you can't use the except formula directly on fields within that nested structure.
To handle this is to reconstruct a new variable.
Saturday
To remove top-level and nested fields in your object, use this:
modified_users = users.map do |user|
user.except(:two_factor_auth_enabled, :signature).merge(
user_fields: user[:user_fields]&.except(:city)
)
end
This removes :two_factor_auth_enabled and :signature from the top-level and :city from the nested user_fields.