cancel
Showing results for 
Search instead for 
Did you mean: 

Array Rename

Majid
New Contributor III

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":[
“”,
]
}

10 REPLIES 10

bojanvelevski
Valued Contributor

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

cjhoward18
Employee
Employee

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

Majid
New Contributor III

@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.

Majid
New Contributor III

@cjhoward18 @bojanvelevski any directions how to approach the above use case.