-
Notifications
You must be signed in to change notification settings - Fork 51
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
YAML output formats whole number floats indistinguishable from integers [formerly: JSON to TOML changes an integer to a float] #3
Comments
Thanks for pointing this out @rafi. JSON does not distinguish between integer and floating point types: I suspect that Go’s |
On the flip side, providing a float produces inconsistent results: $ echo 'qux: 1.0' | yj -yy
qux: 1
$ echo 'qux: 1.0' | yj -yt
qux = 1.0
$ echo 'qux: 1.0' | yj -yj
{"qux":1}
$ echo 'qux: 1.0' | yj -yc
"qux" = 1 |
YAML and TOML both define distinct integer and float types, while JSON and HCL do not. Therefore, these seem correct:
But the reflective conversion should probably preserve the float, so this should be improved:
I suspect there are other conversions with YAML and TOML that don't appropriately preserve floats. I'll take a closer look tonight. |
After more testing, this appears to be an upstream issue with the go-yaml YAML parser. This snippet outputs:
I'll open an issue upstream after I double-check the YAML spec to make sure |
Thanks @sclevine for the awesome response :) |
Happy to help :) Given the response upstream, I'd like to:
Sound good? |
Sounds great, thanks. |
Signed-off-by: Stephen Levine <stephen.levine@gmail.com>
Everything mentioned above should be addressed in v5.0.0, which uses gopkg.in/yaml.v3. Additionally, map order is now preserved across all formats. |
Great stuff @sclevine! |
JSON to TOML changes an integer to a float, this is not expected.
Example:
The text was updated successfully, but these errors were encountered: