-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
JSON: Parsing and serializing numbers, often undesired E notation #1583
Comments
I see that the Serialization spec states (https://qt4cg.org/specifications/xslt-xquery-serialization-40/Overview.html#json-output):
Ideally, we could define a representation that is not implementation-dependent. |
We could use 6.1.6.1.20 Number::toString as a guideline (and preserve the existing rules for |
There is an asymetry between parsing and serializing JSON:
Again, the behavior depends on the implementation. For example, Saxon, eXist and BaseX serialize the xs:decimal 1.00000000000000000000000000001
=> serialize(map { 'method': 'json' }) Do we think it’s advantageous to serialize numeric types differently, or should we rather serialize all as doubles? |
Clearly, adding the I'm a bit reluctant to change the serialization rules. If we change them to be more prescriptive, then some implementations will need to change and users may not like the change. I'm reluctant to add serialization parameters to give users more control. Saxon's rule, incidentally is (a) for xs:decimal, never use exponential notation, (b) for xs:double, use exponential notation only outside the range 1e-18 to 1e+18. That seems to be good enough for most people. |
Yes, an alternative would be to change the parsing. However, I believe this approach would be more invasive than changing serialization.
What is the reason for choosing I believe most users would appreciate it if all implementations behaved similarly. The problem is pretty similar to our |
I guess I was unaware that ECMA had chosen 1e+21 as the threshold. My thinking was primarily to ensure that all integers that had "accidentally" been converted to floating point would be output as integers, and I think 18 is sufficient for that (in fact, 15 probably is). |
If JSON numbers are converted to XML and serialized as JSON, it is confusing to end up with an E notation for large numbers. An example:
Obviously, lossless roundtripping is not possible (
1e20
is a valid JSON number, so we cannot distinguish it from100000000000000000000
), but as the E notation is much less common than integers, maybe we could try to return more numbers in their integer representation if the result would be equivalent?Related: #1445
The text was updated successfully, but these errors were encountered: