08-04-2021 01:01 PM
Hi Team,
I am trying to achieve below. I would need directions on how to achieve below in a mapper or any other way.
Source :
{
“UBER_ID”:[
“1”,
“Integer_pattern”
],
“First_name”:[
“Majid”,
“TextOnly_pattern”
],
“Last_name”:[
“”,
“TextOnly_pattern”
]
}
Target :
I would like to rename the above fields based on the value in the array. Below is the output I am looking at.
{
“Integer_pattern”:[
“1”,
],
“TextOnly_pattern”:[
“Majid”,
],
" TextOnly_pattern":[
“”,
]
}
08-04-2021 01:30 PM
Hi @Majid ,
There must be some more solid conditions for the logic, like, the name of the field will always be the second element in the array. But even if you define those conditions, this output cannot be achieved because you have two fields in the object with the same key, and that is not allowed. Revise and resend the requirements so we can help you better.
Regards,
Bojan
08-04-2021 01:34 PM
Hi @Majid
You should be able to use this expression in a mapper to replace the keys with the last value of the array, as well as remove it from the array:
$.mapKeys((val, key) => val.pop())
What @bojanvelevski said still holds true. However, I believe this is the expression you are looking for
08-05-2021 06:37 AM
@cjhoward18 Thank you. This is renaming the arrays but as there is more than one fields in the object with same key name the output is just keeping the last instance.
@bojanvelevski Thank You. my requirement is to validate each field against different regex. I have used data validator with all possible regex I have and I was trying to rename the fields to corresponding regex name I have provided in data validator snap so that each field will be validated against associated regex. regex name will always be second and last element.
Attaching sample pipeline.
data-validation-regex_2021_08_05 (1).slp (15.3 KB)
If there is any other recommended approach to achieve this please let me know.
08-05-2021 01:04 PM
@cjhoward18 @bojanvelevski any directions how to approach the above use case.