cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Mapper for nest array

pavan_gangisett
New Contributor II

Iโ€™m trying transform the data as below using mapper. Could someone please let me know how this can be done with mapper snap.
Input Schema:
[
department_Id: number,
details: [
{ firstname: string, lastname: string, id: number},
{ firstname: string, lastname: string, id: number}
]
]

Expected Output Schema:
[
department_Id: number,
details: [
{ name: string = firstname+ " "+ lastname, id: number},
{ name: string = firstname+ " "+ lastname, id: number}
]
]

1 ACCEPTED SOLUTION

Think this does what youโ€™re looking for.

image

I used the first mapper to re-map the entries in the details array and then the second mapper to rename the details property to users.

Here is what I was mentioning about using the Mapping Root. This is very helpful for working with nested arrays.

28%20AM

Here is the complete example for you to try out. Good luck with your work.

make-users_2019_06_20.slp (5.5 KB)

View solution in original post

6 REPLIES 6

tlikarish
Employee
Employee

Iโ€™d recommend using the Mapping Root property in the Mapper snap. You can set that to be $.details[*] and that will allow you to transform each element of the details array.

Take a look at this post for another example and feel free to follow up with other questions.

It is not working for me.

image

test_2019_06_20.slp (4.4 KB) here is the pipeline Iโ€™m using to test it.

Hi Pavan,

image
test123_2019_06_20.slp (5.1 KB)

Hi Ajay,

it is not working as expected.
Input Json:
[
{department_Id: 1,
details: [
{ firstname: โ€œaโ€, lastname: โ€œbโ€, id: 1},
{ firstname: โ€œcโ€, lastname: โ€œdโ€, id: 2}
]
},
{department_Id: 2,
details: [
{ firstname: โ€œeโ€, lastname: โ€œfโ€, id: 3},
{ firstname: โ€œgโ€, lastname: โ€œhโ€, id: 4}
]
}
]

Expected Output Json:
[
{department_Id: 1,
users: [
{ name: โ€œa bโ€, id: 1},
{ name: โ€œc dโ€, id: 2}
]
},
{department_Id: 2,
users: [
{ name: โ€œe fโ€, id: 3},
{ name: โ€œg hโ€, id: 4}
]
}
]