Skip to content

math/big: Support string numbers in Int.UnmarshalJSON #49525

@lmittmann

Description

@lmittmann

What version of Go are you using (go version)?

$ go version
go version go1.17.3

Does this issue reproduce with the latest release?

Yes

What did you do?

Try to decode json numbers in string format as big.Int.

What did you expect to see?

String number (e.g. {"val": "123"}) should be unmarshaled to big.Int.

What did you see instead?

String number (e.g. {"val": "123"}) can not be unmarshaled to big.Int.

Proposal

Even though the json spec does allow numbers of any size it is very common to have big numbers in string format, e.g. {"val": "123"} instead of {"val":123}. I propose to add support for reading numbers in string format to big.Int.UnmarshalJSON.
No API change, just a small improvement.

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions