[x3d-public] impact for JSON: ES6 and duplicate object literal properties
John Carlson
yottzumm at gmail.com
Mon Dec 19 09:40:36 PST 2016
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.
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-an
d-definitions-object
Wondering why they might deviate from prior strictness in JSON object model
- duplicate keys can't be represented as an object. Perhaps there is a
site or online discussion that covers this?
Apparently JSON accepts it, even in strict mode, so web won't be broken.
This will be important for JSON linters to catch, unless we want to do
> streaming JSON (we don’t).
>
X3DJSONLD won't catch it unless json schema catches it. X3DJSONLD uses
JSON.parse which isn't strict.
how about jslint, jshint and X3DJSONLD ?
http://jsonlint.com
http://jshint.com
https://github.com/coderextreme/X3DJSONLD
I had trouble getting jsonlint or jshint to operate on your example, they
balked mysteriously until replacing left-quote/right-quote characters.
Also jslint failed silently under IE.
This strict version of your example works:
==============
{ "books":{
"title":"Understanding ECMAScript 6",
"title2":"JavaScript: The Good, the Bad and the Ugly"
}
}
==============
jslint and jshint report "duplicate key" for:
==============
{ "books":{
"title":"Understanding ECMAScript 6",
"title":"JavaScript: The Good, the Bad and the Ugly"
}
}
==============
if ES6 checkbox is selected, jslint still reports: Duplicate 'title'.
So maybe we are OK on this issue?
Probably. Thanks for checking. I don't know if we can test JSON schema
because I think the validators require a JS object.
all the best, Don
--
Don Brutzman Naval Postgraduate School, Code USW/Br brutzman at nps.edu
Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20161219/9527a44a/attachment.html>
More information about the x3d-public
mailing list