Repository navigation
Preserve integer precision when decoding JSON into any - #4017
Merged
Merged
Conversation
elfosardo
force-pushed
the
fix-json-number-extract
branch
from
September 16, 2026 15:56
9ba32b1 to
55e7080
Compare
mandre
reviewed
Sep 17, 2026
mandre
left a comment
Contributor
There was a problem hiding this comment.
Thanks. I believe there are more places where we need to decode json using UseNumber().
We may want to directly fix ExtractInto() but that wouldn't be great because it's would change the any-typed field behavior for all callers.
Instead, we should inline the call to ExtractInto() from extractIntoPtr(), using UseNumber():
Lines 75 to 79 in d575108
It should become:
var m map[string]any
b, err := json.Marshal(r.Body)
if err != nil {
return err
}
dec := json.NewDecoder(bytes.NewReader(b))
dec.UseNumber()
err = dec.Decode(&m)return err
}Extract() round-trips Result.Body through json.Marshal. Decoding into any as float64 rounds signed 64-bit maximum values, so BIOS upper_bound 9223372036854775807 fails unmarshal into int. Use json.Decoder.UseNumber() so those integers survive Extract().
elfosardo
force-pushed
the
fix-json-number-extract
branch
from
September 17, 2026 08:42
55e7080 to
97b1e61
Compare
mandre
approved these changes
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract() round-trips Result.Body through json.Marshal. Decoding into any as float64 rounds signed 64-bit maximum values, so BIOS upper_bound 9223372036854775807 fails unmarshal into int. Use json.Decoder.UseNumber() so those integers survive Extract().
Fixes #4016