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: Decoding returns error when case-insensitive keys overlap and not all struct fields defined #54404

Closed
sdcoffey opened this issue Aug 11, 2022 · 1 comment

Comments

@sdcoffey
Copy link

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

1.18

Does this issue reproduce with the latest release?

Yes, reproducible with go 1.19

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

go env Output
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/steve/Library/Caches/go-build"
GOENV="/Users/steve/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/steve/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/steve/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/steve/yuzu/crypto-stream-source/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/q_/381gr8255wl427x33rzsyvk80000gn/T/go-build2527350202=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Go Playground

Given this block of JSON (example taken from a Binance websocket payload):

{
  "e": "24hrTicker", 
  "E": 123456789
}

encoding/json will return an error while unmarshaling into this struct:

type UnsuccessfulUnmarshal struct {
	TimeStamp int64 `json:"E"`
}

but not this struct:

type SuccessfulUnmarshal struct {
	Event     string `json:"e"`
	TimeStamp int64  `json:"E"`
}

What did you expect to see?

No error returned when only some of the fields in the json payload are defined in the destination struct

What did you see instead?

This error returned:

json: cannot unmarshal string into Go struct field UnsuccessfulUnmarshal.E of type int64
@seankhliao
Copy link
Member

Duplicate of #14750

@seankhliao seankhliao marked this as a duplicate of #14750 Aug 11, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants