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 !