-
Notifications
You must be signed in to change notification settings - Fork 14
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
multiline string should require trailing \ #10
Comments
\ at the end consumes the newline, flattening the result. Otherwise the newline is kept. |
Yes; I could have specifically disallowed double and single quoted strings and only allowed it for backtick strings; but there wasn't a lot of benefit for the complexity that added. |
It have at least one benefit that keep JSON6 as "strict subset of JavaScript" which means you could always paste the whole JSON6 code into JS source file without fear, and you could just eval(JSON6) if do not care about security. In fact I think "strict subset of JS" is the only reason why JSON or JSON5 or JSON6 could popular than other format. Or why not use yaml ? 😁 |
I've seen more than one dev nit pick the "strict subset of JS" bit in JSON5 and friends and I always assumed it was devs being pedantic. This is something that could be tweaked, but as long as it's not bugging out someone's code, it's probably fine. I use JSON, or JSON flavors like JSON5 or JSON6, because it's close enough to JS that folks in the JS ecosystem get it. I use yaml, because I'm forced to for other tools, and still don't quite understand all the whitespace and property rules. |
what issue does this cause you? While considering implementing this, was going through the code, and found streaming processing for strings was broken; also some character escapes didn't work very well. Think anyone will miss octal with just a leading 0 and no o as in 0o ? It's extra work and a minor performance hit (1-2%) to process for the additional case... |
@jdalton When I mention YAML or other formats, I'm not trying to convince anybody YAML format is better than JSON-like format, at least not in this issue. You can change YAML to any other format for example CSON, TOML, etc. What I'm trying to express is that there are some important factors which make JSON popular, especially JSON is a so anti-human-friendly format. I think “be strict subset of JS” is one of the key factor. To be honest, I myself am fine with a JSON-like format with a little incompatibility with JavaScript. But I'm sure many will treat such incompatibility as a barrier of adoption, especially you write such commitment is in the README , but actually not follow it. The simple solution is change the words in the README from “a strict subset of JavaScript” to “a loose subset of JavaScript” or “a superset of JSON/JSON5”. But I still think we can recheck all the incompatibilities to see whether it's useful enough. What I'm concern is the interoperability of the formats and the tools, parsers for them. We do not want too many branches of JSON-like formats. I could imagine someone fork JSON6 and remove the incompatibilities and release it as JSON7...
@d3x0r Yes I was trying to raise this issue too.
No , I never talk about performance. Besides syntax issues, there are also semantic issues. For example allow |
NaN is allowed in Json5. I'll work on some rewording of the README though. |
Being more correct is a good thing. The minor perf hit can be offset or mitigated I'm sure. |
'being more correct' javascript itself doesn't take 0123 as octal... Only 0o123. |
By more correct I mean following the language precedents and specification when possible. |
Yes, there was an old issue: json5/json5-spec#2 The author of JSON5 said
As this rule (can transpile to JSON), |
and that was closed with ... "Leaving Infinity and NaN as is for now." Updated documenation... https://github.com/d3x0r/json6#caveats "Objects can have a single trailing comma. Excessive commas in objects will cause an exception. '{ a:123,,b:456 }' is invalid." Reverted const SUPPORT_LEAD_ZERO_OCTAL = true; to support leading 0 octal interpretations. |
It seems current syntax allow multiline string without trailing
\
, at least in the exampleBut it's not valid js, and if allow this, it will break the design goal of "strict subset of JS".
The text was updated successfully, but these errors were encountered: