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

Fix loading large integers from JSON files #334

merged 3 commits into from Sep 22, 2022


Copy link

@severb severb commented Sep 21, 2022

%v uses E notation to format floats with more than 6 digits. Since JSON numbers are always floats, Kong breaks when loading large integers from JSON files.

Copy link

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thanks!

@alecthomas alecthomas merged commit c62bf25 into alecthomas:master Sep 22, 2022
Copy link

I suspect this will still fail with very large integers, e.g. max Int64: 9223372036854775807 if it's marshalling into a float64, as it's not possible to represent this number exactly as a float64.

I came across a similar problem in Prana when unmarshalling JSON Kafka messages which have large numbers in their fields. The solution in Prana was not to use the default Go Json unmarshalling (which treats all numbers as float64), but to unmarshall into a map, preserving the original form, then doing a strconv.parseInt(...) on the field to convert it into a int64 without losing precision.

Copy link

Hey @alecthomas - any thoughts on the above?

Copy link

If the target field is a float64 then that would be expected wouldn't it? If you want to support very large integers try int64, big.Int, or big.Float, do those work?

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

Successfully merging this pull request may close these issues.

None yet

3 participants