Is there a way to group Dynamic Object keys of a JSON file? I want the object values for each key to be grouped accordingly.
I attempted to use map and reduce functions to achieve this grouping, but the results did not turn out as I had expected.
Below is an example of my JSON Object:
var data = [
{
// JSON objects here...
}
]
Here is the code snippet that I tried but didn't produce the desired outcome:
var x = data.map((e) => {
var el = {}
el[e.data.error.cause.root.Extracted.Body.Error.ErrorString] =
[e.data.error.cause.root.Extracted.Body.Error.info];
return el;
})
console.log(x);
The result I obtained was:
[
{
"NotFound": {....}
},
{
// More results like above...
}
]
What I was expecting instead was:
[
{
"NotFound": [
{
// Nested objects under "NotFound" key
},
{
// Another nested object under "NotFound" key
}
]
},
{
// Other keys and their respective nested objects
}
]