Recently, I've been working on a Typescript project where I encountered the need to reformat a JSON object. The original object consists of an array of objects with keys and corresponding values. My goal is to separate the keys into one array and the data into separate arrays.
Here is the current structure of the object:
[
{
"id": "1",
"ser": null,
"IP": null,
"host": "",
"type": "Web",
"auth": ""
},
{
"id": "2",
"ser": null,
"IP": "191.174.230.02",
"host": "",
"type": "Proxy",
"auth": ""
}
]
This is the desired outcome:
[
"id",
"ser",
"IP",
"host",
"type",
"auth"
],
[
"1",
null,
null,
"",
"Web",
""
],
[
"2",
null,
"191.174.230.02",
"",
"Proxy",
""
]
To achieve this structure, I intend to introduce a new property called values
in the object:
{
"values": [
[
"id",
"ser",
"IP",
"host",
"type",
"auth"
],
[
"1",
null,
null,
"",
"Web",
""
],
[
"2",
null,
"191.174.230.02",
"",
"Proxy",
""
]
]
}