const map1 = new Map([
['foo', 'bar'],
['baz', 42]
]);
const obj = Object.fromEntries(map1);
// { foo: 'bar', baz: 42 }
//To get back the map:
const map2 = new Map(Object.entries(obj));
const mapToJson = (map) => JSON.stringify(Object.fromEntries(map));
const map = new Map([
['user1', 'John'],
['user2', 'Kate'],
['user3', 'Peter'],
]);
const json = mapToJson(map);
// {"user1":"John","user2":"Kate","user3":"Peter"}
console.log(json);