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: include field name in error for decoding unquoted number into",string" tag #67774

Open
kokizzu opened this issue Jun 2, 2024 · 1 comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@kokizzu
Copy link

kokizzu commented Jun 2, 2024

Go version

all version affected

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/asd/.cache/go-build'
GOENV='/home/asd/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/asd/go/pkg/mod'
GOOS='linux'
GOPATH='/home/asd/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/a/go.mod'
GOWORK='off'
CGO_CFLAGS='-Wno-return-local-addr'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2911848713=/tmp/go-build -gno-record-gcc-switches'

What did you do?

try unmarshalling json quoted with int, with and without ",string", all combination only works

  • quoted number - with ,string = works
  • unquoted number - with , string = doesnt work
  • quoted number - without ,string = doesnt work
  • unquoted number - without ,string = works

this is quite annoying if there's bunch of fields in the struct (eg. 24+) and the error super unclear json: invalid use of ,string struct tag, trying to unmarshal unquoted value into uint64, which field?

What did you see happen?

just json: invalid use of ,string struct tag, trying to unmarshal unquoted value into uint64

What did you expect to see?

either clearer error message showing which field like: json: invalid use of ,string struct tag, trying to unmarshal unquoted value into uint64 field MoneyIDR

or more permissive unmarshalling option that accept both quoted or unquoted number that targets to number field (int64/uint64) so dont have to use js.Number

@seankhliao seankhliao changed the title json/marshal: clearer error message for unmarshalling integer with ",string" encoding/json: include field name in error for decoding unquoted number into",string" tag Jun 2, 2024
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 2, 2024
@seankhliao
Copy link
Member

similar to #22816

@gabyhelp gabyhelp added the Bug label Jan 6, 2025
@jba jba added BugReport Issues describing a possible bug in the Go implementation. and removed Bug labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants