I'd like to start using ES6 Map instead of JS objects but I'm being held back because I can't figure out how to JSON.stringify()
a Map
. My keys are guaranteed to be strings and my values will always be listed. Do I really have to write a wrapper method to serialize?
Javascript – How to JSON.stringify an ES6 Map
dictionaryecmascript-6javascriptjson
Best Answer
Both
JSON.stringify
andJSON.parse
support a second argument.replacer
andreviver
respectively. With replacer and reviver below it's possible to add support for native Map object, including deeply nested valuesUsage:
Deep nesting with combination of Arrays, Objects and Maps