Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

First add an options objects parameter to JSON.stringify and JSON.parse #4

Closed
allenwb opened this issue May 10, 2018 · 2 comments
Closed

Comments

@allenwb
Copy link
Member

allenwb commented May 10, 2018

This proposal is one of many tweaks that could be made to JSON.stringify/parse to make them more versatile. But many of them need to be opt-in either for backwards compatibility or because they are not always applicable. This could be worked around by added additional stringify/parse methods with new names but that is a very heavy weight approach.

A better approach is to added additional control parameters to stringify/parse.

Note that the current semantics for the second parameter to both methods only recognizes function or native Array objects. All other objects passed in that position are ignored. That means that it would be backwards compatible to revised their specification to accept an options object as the second parameter. Such an option object should be defined to have option properties corresponding to the existing positional options.

As the first step in enhancing stringify/replace I think you should specify such an option object invention and then use it for opt-ins to new functionality or breaking changes.

@mathiasbynens
Copy link
Member

Having to opt-in to sensible defaults would be much less useful than just fixing the current behavior. Still, this could be an alternative if the current proposal doesn’t work out.

@mathiasbynens
Copy link
Member

Just to clarify, JSON.parse doesn’t need any changes with this proposal.

The idea to add an options bag to JSON.stringify was discussed during today’s TC39 meeting and there was consensus that, for this particular proposal, fixing the default would be better.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants