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

Danielle McLean gopsychonauts at
Fri Sep 30 01:30:20 UTC 2016

From: Olivier Lalonde (mailto:olalonde at
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.

More information about the es-discuss mailing list