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

Creating Nested Json for REST API

Senthilnaga91
New Contributor II

Hello All,

In my use case, I have a nested JSON as an input, I want to do some transformation before I create a nested JSON which I am going to post it in a REST API,

InPut JSON:

[
{
โ€œCustomerโ€: {
โ€œNameโ€: Sam
โ€œCityโ€: โ€œChicagoโ€,
โ€œEmail":""abc@ggg.comโ€
โ€œaccountsโ€: [
{
โ€œaccountIdโ€: 3567361088,
โ€œaccountBalanceโ€: 9453.563,
โ€œcreatedโ€: โ€œ2014-09-21โ€
},
{
โ€œaccountIdโ€: 12345,
โ€œaccountBalanceโ€: 9444.563,
โ€œcreatedโ€: โ€œ2014-09-21โ€
}
]
}
}
]

Output JSON:

[
{
โ€œCustomer_Entryโ€: {
โ€œNameโ€: Sam
โ€œaccounts_detailsโ€: [
{
โ€œacc_Idโ€: 3567361088,
โ€œacc_Balanceโ€: 9453.563,
},
{
โ€œacc_Idโ€: 12345,
โ€œacc_Balanceโ€: 9444.563,
}
]
}
}
]

The challenge is after the transformation, I retain few keys including the nested keys and also renamed them into different values. Whatโ€™s the best way to design the pipeline for this case.

Thanks in Advance.

1 ACCEPTED SOLUTION

AleksandarAngel
Contributor III

Hello and welcome @Senthilnaga91,

You can achieve the needed transformations by using two Mapper Snaps like in the picture below.

image

In the first Mapper weโ€™re mapping the Account Details array:

image

And, in the second one weโ€™re mapping the Customer Entry object:
image

Also you can refer to the sample pipeline attached below.

sl-comm-nested-json-api_2023_05_30.slp (5.5 KB)

Let me know if this helps you.

Regards,
Aleksandar.

View solution in original post

2 REPLIES 2

AleksandarAngel
Contributor III

Hello and welcome @Senthilnaga91,

You can achieve the needed transformations by using two Mapper Snaps like in the picture below.

image

In the first Mapper weโ€™re mapping the Account Details array:

image

And, in the second one weโ€™re mapping the Customer Entry object:
image

Also you can refer to the sample pipeline attached below.

sl-comm-nested-json-api_2023_05_30.slp (5.5 KB)

Let me know if this helps you.

Regards,
Aleksandar.

Senthilnaga91
New Contributor II

It worked, Thank you @AleksandarAngelevski !