I am currently working on a typescript file that is receiving a JSON response from an external API. I am in need of assistance to convert the received JSON into a different format. Could someone please help me with this JSON conversion task?
Sample JSON data received from the API:
type here
Employees: [
{ empid : 12345 },
{ empName: "John Doe" },
{ gender: "Male" },
{ hobbie: "Book" },
{ empid : 12347 },
{ gender: "Male" },
{ hobbie: "Gym" },
{ empid : 12346 },
{ empName: "Jill Doe" },
{ gender: "Female" },
{ hobbie: "Sport" },
.
.
.
]
The desired JSON format for conversion is as follows:
type here
finalEmployee: [
{
empName : "John Doe",
empDetails: [
{
serialNo : 1,
empid: 12345,
gender : "Male",
hobbie : "Book"
},
{
serialNo : 2,
empid: 12347,
gender : "Male",
hobbie : "Gym"
}
]
},
{
empName : "Jill Doe",
empDetails: [
{
serialNo : 2,
empid: 12346,
gender : "Female",
hobbie : "Sport"
}
]
},
.
.
.
]
I am having difficulty splitting the data into the required format.