[
{
"id": 0,
"type": "Left",
"count": 3,
"accessories": {
"aa": "V S B",
"bf": "H",
"dc": "P E"
}
},
{
"id": 1,
"type": "Right",
"count": 2,
"accessories": {
"qw": "L",
"bm": "K L"
}
},
...
]
[
{
"name": "Name #0",
"attributes": [
{
"trait_type": "accessory",
"value": "V S B"
},
{
"trait_type": "accessory",
"value": "H"
},
{
"trait_type": "accessory",
"value": "P E"
},
{
"trait_type": "type",
"value": "Left"
}
]
},
...
]
const data = [
{
id: 0,
type: 'Left',
count: 3,
accessories: {
aa: 'V S B',
bf: 'H',
dc: 'P E',
},
},
{
id: 1,
type: 'Right',
count: 2,
accessories: {
qw: 'L',
bm: 'K L',
},
},
];
const newData = data.map((item) => ({
name: `Name #${item.id}`,
attributes: Object.values(item.accessories).map((accessory) => ({
trait_type: 'accessory',
value: accessory,
})).concat([{
trait_type: 'type',
value: item.type,
}]),
}));
console.log(newData);