I am facing an issue with converting a JSON structure into another format. I would appreciate any help or suggestions on this matter. I have tried different methods and alternatives for conversion, but I am still searching for the most efficient way to accomplish it.
// ORIGINAL
{
Monday: {
Transactions: [
{Amount: 100, Status: "Cleared"},
{Amount: 200, Status: "Pending"},
{Amount: 300, Status: "Failed"}
]
},
Tuesday: {
Transactions: [
{Amount: 700, Status: "Cleared"},
{Amount: 800, Status: "Pending"},
{Amount: 900, Status: "Failed"}
]
},
Wednesday: {
Transactions: [
{Amount: 400, Status: "Cleared"},
{Amount: 500, Status: "Pending"},
{Amount: 600, Status: "Failed"}
]
}
}
// EXPECTED OUTPUT
{
Cleared: {
Transactions: [
{Amount: 100, Day: "Monday"},
{Amount: 700, Day: "Tuesday"},
{Amount: 400, Day: "Wednesday"}
]
},
Pending: {
Transactions: [
{Amount: 200, Day: "Monday"},
{Amount: 800, Day: "Tuesday"},
{Amount: 500, Day: "Wednesday"}
]
},
Failed: {
Transactions: [
{Amount: 300, Day: "Monday"},
{Amount: 900, Day: "Tuesday"},
{Amount: 600, Day: "Wednesday"}
]
}
}