[x3d-public] impact for JSON: ES6 and duplicate object literal properties

Yves Piguet yves.piguet at gmail.com
Mon Dec 19 10:47:15 PST 2016


ECMAScript 2015 is very clear about what it considers as valid JSON; see http://www.ecma-international.org/ecma-262/6.0/#sec-24.3.1.1

> It is not permitted for a conforming implementation of JSON.parse to extend the JSON grammars. If an implementation wishes to support a modified or extended JSON interchange format it must do so by defining a different parse function.
> 
> NOTE In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten

Multiple fields with the same key are valid in JSON, but useless: you must not preserve them upon input.

Now one might want to disregard the ECMAScript JSON.parse way of reading JSON, but imo that would be a bad choice.

Yves


> On 19 Dec 2016, at 18:58, <yottzumm at gmail.com> <yottzumm at gmail.com> wrote:
> 
>  
>  
>  
>  
> On Dec 19, 2016 12:03 PM, "Don Brutzman" <brutzman at nps.edu> wrote:
> Hmmm, maybe OK?  Here are some tests.
> Maybe.   I'd like to put "use strict"; in front of it and run it through some browsers but I've been giving my hands a break. 
>  
> Codepen.io reports an error in chrome.
>  
> 
> 
> On 12/18/2016 6:01 AM, yottzumm at gmail.com wrote:
> Note that in ES6, even in strict mode, the following will not cause an error:
> 
> var books = {
>                 title: “Understanding ECMAScript 6”,
>                 title: “JavaScript: The Good, the Bad and the Ugly”
> };
> 
> However,
> 
> books.title === “JavaScript: The Good, the Bad and the Ugly”
>  
> Might you know the ES6 specification paragraph?
> 
>         http://www.ecma-international.org/ecma-262/6.0/#sec-terms-and-definitions-object
> 
> There are two mentions of “object literal” in standard and they appear unrelated.  It’s mentioned under “Duplicate Object Literal Properties” on page 75 of Understanding ECMAScript 6:
>  
>                 “But in ECMAScript 6, the duplicate property check was removed. Strict and non-strict mode code no longer check for duplicate properties.”
>  
> I think maybe it’s just that the JSON parsers don’t catch it.
>  
> John
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org




More information about the x3d-public mailing list