I have a JSON of music audio metadata with several tracks in a following structure:
var jsonObj = {
tracks: [
{ title: 'Another',
artist: 'Ataxia',
album: 'Automatic Writing',
year: '2004',
duration: 382
}]
};
And I want to transform it to have a following grouped structure:
var jsonObj = {
artists: [
{ name: 'Ataxia',
albums: [
{ name: 'Automatic Writing',
year: '2004',
tracks: [
{ title: 'Another',
duration: '382'
}]
}]
}]
};
Of course I tried doing it using pure JavaScript forEach() methods but it's a hell load of repetitive, immersive code and I'm looking for some smart solution. It could rely on some external Node.js package or JavaScript library.
byProperty,groupByor so