Forum Discussion

Senthilnaga91's avatar
Senthilnaga91
New Contributor III
3 years ago
Solved

Creating Nested Json for REST API

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.

  • That won’t be a problem here, because I’m using destructuring assignment ( the three dots ) before the $group array ...$group, this will always work for every $group array regardless of the array size, you don’t have to get each index from the $group array, just use ...$group, this will destructure the array and will be the same as writing $group[0]... $group[n] multiple times.

2 Replies

  • aleung's avatar
    aleung
    Contributor III

    Can you provide details on which snap fails? better yet, show us your pipeline