'Need to create a single JSON response from multiple input Objects
I am creating a middleware orchestration service, where I am calling a bunch of endpoints to get data from the backend database and have all those individual responses as JSON.
I need to create one single JSON output for my front-end application. Below are the three separate JSON responses from my backend and the output which I need to feed into the web application.
How can I transform the output to the required JSON?
JSON-1
[
{
"cartFriendlyName": "Morelia spilotes variegata",
"cartIsActive": true,
"cartMFCCode": "NAP01",
"cartZipCode": 60540,
"cartID": "NAP01-55"
},
{
"cartFriendlyName": "Geococcyx californianus",
"cartIsActive": true,
"cartMFCCode": "NAP01",
"cartZipCode": 60540,
"cartID": "NAP01-93"
}
]
JSON-2
[
{
"itemID": 1,
"qtyOnHand": 20,
"cartID": "NAP01-55"
},
{
"itemID": 4,
"qtyOnHand": 10,
"cartID": "NAP01-55"
}
]
JSON-3
[
{
"itemID": 1,
"qtyOnHand": 18,
"cartID": "NAP01-93"
},
{
"itemID": 3,
"qtyOnHand": 50,
"cartID": "NAP01-93"
}
]
How Can I get my output JSON as the following?
{
"data": [
{
"cartID": "NAP01-55",
"cartInfo": {
"cartFriendlyName": "Morelia spilotes variegata",
"cartZipCode": 60540
},
"cartItems": [
{
"itemID": 1,
"qtyOnHand": 20
},
{
"itemID": 4,
"qtyOnHand": 10
}
]
},
{
"cartID": "NAP01-93",
"cartInfo": {
"cartFriendlyName": "Geococcyx californianus",
"cartZipCode": 60540
},
"cartItems": [
{
"itemID": 1,
"qtyOnHand": 18
},
{
"itemID": 3,
"qtyOnHand": 50
}
]
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
