Proposal: add an option to omit prototype of objects created by JSON.parse()

Rick Waldron waldron.rick at gmail.com
Thu Oct 6 19:50:56 UTC 2016


var o = JSON.parse('{}');
Object.setPrototypeOf(o, null);


Rick

On Thu, Sep 29, 2016 at 9:30 PM Danielle McLean <gopsychonauts at gmail.com>
wrote:

> From: Olivier Lalonde (mailto:olalonde at gmail.com)
> Date: 30 September 2016 at 07:21:10
>
> > Given that JSON.parse doesn't necessarily return an object, would the
> noPrototype option would be ignored on e.g. `JSON.parse('"some string"')`
> or `JSON.parse('true')`?
>
> The noPrototype option should set the behaviour whenever the parser
> encounters a JSON object (i.e., key-value pairs wrapped in curly
> braces). If the JSON text to be parsed does not contain any objects,
> then the option will have no effect. 'true', 'some string', and
> '[1,2,3,"four"]' are examples of JSON texts which would not be
> affected by the noPrototype option. (Note that although an array is a
> *JavaScript* object, it's not a *JSON* object.)
>
> Conversely, if the JSON text to be parsed contains multiple objects -
> for instance, `JSON.parse('[{"first": 1}, {"second": 2}, {"third":
> 3}]', {noPrototype: true})` - then *all* of those objects should be
> constructed with a null prototype.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161006/c97bf440/attachment.html>


More information about the es-discuss mailing list