Currently, I am utilizing core-js
for the Map collection because it appears that ES7 Map
includes a Map to JSON feature that is absent in ES6 Map
.
(ES6): JSON.stringify(new Map().set('myKey1', 'val123').set('myKey2', 'val456')); => {}
However, ES 7 seems to introduce unnecessary square brackets to the key value pairs
For example (ES7): JSON.stringify(new Map().set('myKey1', 'val123').set('myKey2', 'val456')); => [["myKey1","val123"],["myKey2","val456"]]
where I was expecting something like this:
{"myKey1": "val123","myKey2":"val456"}
Any assistance would be greatly appreciated!
EDIT: Upon closer inspection, I realized there was a mistake in the JSON I provided, but that was simply a typo made while posting the question.
Essentially, I am using TypeScript to create a new Map
containing string key-value pairs like
new Map<string, string>()
I am anticipating the JSON output of such a Map to be
{"myKey1": "val123","myKey2":"val456"}
and would appreciate any suggestions on how to achieve this desired result.