-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON5.parse("{1:true}"); #10
Comments
Yep — this in invalid JS too:
Unquoted keys have the same rules as variables ("identifiers"). Here's a reference: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Variables I'll update the readme to be clearer about this. |
Oh! Sorry |
No worries. =) |
An example of this notation can be found on the link you posted in the "String literals" chapter: |
This is currently working for me. From the node prompt:
If there's something unexpected, then please raise a new issue. ps- you are correct that |
|
Yes, you're right @rlidwka:
(Interestingly, the first case gives that syntax error in Chrome, but not Node.) That we reject this is currently expected, because I was under the impression that ES5's spec on object keys applies the same rules for unquoted keys as it does to variable names (hence the link I shared above). If it's valid ES5 though, perhaps we should allow this... It'd be nice to confirm that this is allowed per ES5 though, not just an "it-so-happens" behavior of existing implementations. |
It can happen because first "{" is treated as a beginning of a block (as in If you want to test such kind of things reliably, add parentheses around the statement. This: |
Yep, I'm aware of the ambiguity, I was just surprised that two different instances of the same JS implementation treat the ambiguity differently. |
Closing as JSON5 will not support numeric literals as property names until there is enough demand for it. #55 is now the official issue regarding this. |
JSON5.parse("{1:true}");
<== errorThe text was updated successfully, but these errors were encountered: