Description
Hello,
The documentation states that:
Starlark float values are encoded using decimal point notation, even if the value is an integer.
This suggests that float(1) should be encoded as 1.0, similar to Python:
>>> import json
>>> json.dumps([1.0])
"[1.0]"
However, Starlark uses %g
formatting, which truncates trailing zeros and the decimal point. Hence:
>>> json.encode([1.0])
"[1]"
It appears that "encoding/json" module in Go exhibits the same behavior.
Even a comment in the Starlark source code misleadingly states that a float representation "always contains a decimal point":
Line 150 in 1207426
In my opinion, since Starlark tries to be similar to Python, the JSON serialization should behave the same way and preserve the information about the floating-point type. I don't expect that changing the formatting will break existing code, but even so the current implementation will definitely lead to bugs. However, in case you decide not to change anything here, please update the documentation accordingly.
Thank you!