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

encoding/json: "string" option doesn't apply to *big.Int #57970

Closed
xoba opened this issue Jan 24, 2023 · 1 comment
Closed

encoding/json: "string" option doesn't apply to *big.Int #57970

xoba opened this issue Jan 24, 2023 · 1 comment

Comments

@xoba
Copy link
Contributor

xoba commented Jan 24, 2023

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

$ go version
go version go1.20rc3 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mra/Library/Caches/go-build"
GOENV="/Users/mra/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mra/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mra/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/mra/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/mra/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20rc3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tj/h518gq8n7h1_8t28ql6lnnb40000gn/T/go-build3734188390=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

from https://pkg.go.dev/encoding/json (see quote below), i expected *big.Int to be quoted with the "string" tag option, since by any reasonable interpretation, *big.Int is an "integer". on the other hand, *big.Int does render as arbitrarily large integers in json anyway, but that introduces incompatibility with javascript which uses IEEE-754 floats.

The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs

see https://go.dev/play/p/dDMU2qYMcqL for how encoding/json package
ignores "string" tag option for *big.Int.

What did you expect to see?

{"Value":"2"}

What did you see instead?

{"Value":2}

@seankhliao
Copy link
Member

Duplicate of #36099

@seankhliao seankhliao marked this as a duplicate of #36099 Jan 24, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
@golang golang locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants