Skip to content
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

Json to Yaml Mangling Large Integer #2122

Open
MatthewChau opened this issue Aug 6, 2024 · 2 comments
Open

Json to Yaml Mangling Large Integer #2122

MatthewChau opened this issue Aug 6, 2024 · 2 comments
Labels

Comments

@MatthewChau
Copy link

MatthewChau commented Aug 6, 2024

When converting from json to yaml, a large integer is getting converted to scientific notation. This leads to problems with rounding.

Version of yq: 4.44.2
Operating system: linux_amd64 (running in WSL)
Installed via: Binary release

Input json

"schema": {
    "maximum": 9223372036854775807,
    "minimum": 1,
    "type": "integer",
    "format": "int64"
}

Command

./yq_linux_amd64 -P -oy test.json

Actual behavior

schema:
    maximum: 9.223372036854776e+18
    minimum: 1
    type: integer
    format: int64

Expected behavior

schema:
    maximum: 9223372036854775807
    minimum: 1
    type: integer
    format: int64

Additional context
Expected behavior matches actual behavior when testing with v4.14.1

./yq_linux_amd64 eval -P -oy test.json
@dhduvall
Copy link

Even worse (IMO):

❯ echo "3681579493102783500" | yq --input-format json
3681579493102783488

Actually, all numbers from 3681579493102783232 to 3681579493102783744 convert to 3681579493102783488. The next set of numbers lower convert to 3681579493102782976.

@MatthewChau
Copy link
Author

Is this less of a bug and more of a behavior change? Although I see that this issue has been brought up before in older versions. #245
Did some additional testing and the change happens with v4.32.1.

./yq_linux_amd64_v4.31.2 -oy test.json

Output

"schema": {"maximum": 9223372036854775807, "minimum": 1, "type": "integer", "format": "int64"}
./yq_linux_amd64_v4.32.1 -oy test.json

Output

schema
---
maximum: 9.223372036854776e+18
minimum: 1
type: integer
format: int64
./yq_linux_amd64_v4.32.1 -oj test.json

Output

"schema"
{
    "maximum": 9223372036854776000,
    "minimum": 1,
    "type": "integer",
    "format": "int64"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants