json5 / json5-spec

The JSON5 Data Interchange Format
https://spec.json5.org
MIT License
49 stars 11 forks source link

Support number separators? #23

Closed brimworks closed 4 years ago

brimworks commented 4 years ago

Given that JSON5 is JSON for humans, it would sure be nice if decimal numbers could be written with a separator so it is clear what magnitude a number is. For example, writing 1,000,000,000 is clearly a million, but 1000000000 is unclear. Perhaps this should even be a request of the ECMA spec? In other languages, I've seen _ used as the separator so 1_000_000_000 is one billion and by using underscore it bypasses all the localization problems (some locales write numbers with dots and not comma) and the parser problems (comma is used to delimit elements of an array).

jordanbtucker commented 4 years ago

Thanks for your suggestion, numeric separators is a stage 3 proposal for ECMAScript. Unfortunately, it is not compatible with ES5, so it won't be added to JSON5. We aim to keep JSON5 simple by only adding features from ES5. This keeps JSON5 easy to implement and prevents scope creep.

brimworks commented 4 years ago

Oh, it looks like this might be a possible addition (since it is in stage 3). How would you feel if certain implementations did support number separators as valid grammar? In particular, I've created a Java implementation and was considering allowing for underscores in numbers.

jordanbtucker commented 4 years ago

Feel free to extend JSON5, however if you do, please don't call it JSON5 anymore. If your library can parse JSON5-compliant documents, that is fine to promote that. You could say, for example, that your library is backward compatible with JSON5.

However, if your library can generate documents not compliant with JSON5, then please don't call those documents JSON5. A document that contains numeric separators, but is otherwise compatible with JSON5, is not a JSON5 document. Make sense?

brimworks commented 4 years ago

Yep, makes sense :).