I have a Map that is set up like this
const directory = new Map()
.set('John', { age:25, gender: 'M'} )
.set('Mary', { age:51, gender: 'M'} )
.set('Sam', { age:15, gender: 'M', id: 322 } )
.set('Jane', { age:15, gender: 'M', paid: true } );
I wish to transform this to an array of jsons with a new property "name" for each of the key from the map:
[
{ "name": "John", "age":25, "gender": "M" },
{ "name": "Mary", "age":51, "gender": "F" },
{ "name": "Sam", "age":15, "gender": "M", "id": 322 },
{ "name": "Jane", "age":19, "gender": "F", "paid": true }
]
I tried JSON.stringify([...directory]) and bunch of other stuff but the not sure of any efficient way of including the key as part of the json.