{Set,Map}.prototype.toJSON ?
- Stage: Unstaged
- Status: Inactive
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
The proposal addresses the unhelpful output of JSON.stringify on Map and Set instances, which currently returns '{}'. It suggests adding default toJSON methods to Set.prototype and Map.prototype, so that JSON serialization returns an array of entries or values respectively. Userland code can still override these methods on specific instances.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Map-Set.prototype.toJSON
An ECMAScript proposal. Currently at Stage 0.
This proposal was brought before the committee in the March 2016 meeting, and thoroughly rejected. Details
Problem
Here is the current situation:
This result is unhelpful. Same goes for Map.
Proposal
This proposal is about providing a sensible default to the common operation of JSON serialization via default toJSON implementations on Set.prototype and Map.prototype. Of course, userland code can always shadow this value on specific instances.
Map.prototype.toJSON
The essence of the proposal is captured in this snippet (spec in markdown or HTML):
Set.prototype.toJSON
The essence of the proposal is captured in this snippet (spec in markdown or HTML):
Discussion
There might be a web compat concern if code using native Map and Set or polyfill relies on the current JSON.stringify behavior.
Licence
This work is dedicated to the public domain. It is CC0 licenced.