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

Bug Report: JSON Deserialization Case Sensitivity Issue in Go #67689

Closed
acczefly opened this issue May 29, 2024 · 2 comments
Closed

Bug Report: JSON Deserialization Case Sensitivity Issue in Go #67689

acczefly opened this issue May 29, 2024 · 2 comments

Comments

@acczefly
Copy link

acczefly commented May 29, 2024

Go version

go version go1.22.3 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/xxxxxx/Library/Caches/go-build'
GOENV='/Users/xxxxxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/opt/workspace/golang/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/opt/workspace/golang'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.3/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c  '
CGO_ENABLED='1'
GOMOD='/opt/tmp/go.mod'
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/3q/0tmgj6rd7d15y9lgxmykjnp40000gn/T/go-build860661036=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

package main

import (
	"encoding/json"
	"fmt"
)

type Ticker1 struct {
	// EventType string `json:"e"`
	EventTime int64 `json:"E"`
}

type Ticker2 struct {
	EventType string `json:"e"`
	EventTime int64 `json:"E"`
}

func main(){
	raw := `{"A":"0.099912","B":"0.089148","C":1716983452351,"E":1716983452351,"F":1364420,"L":1447324,"O":1716897052351,"P":"-1.994","Q":"0.00350000","a":"3821.95000000","b":"3821.93000000","c":"3821.94000000","e":"24hrTicker","h":"4667.30000000","l":"3100.00000000","n":82905,"o":"3899.69500000","p":"-77.75000000","q":"19657826.75182800","s":"ETHUSDT","v":"5113.89840000","w":"3844.00025464","x":"3899.69500000"}`

	var ticker1 Ticker1
	fmt.Println(json.Unmarshal([]byte(raw), &ticker1))

	var ticker2 Ticker2
	fmt.Println(json.Unmarshal([]byte(raw), &ticker2))
}

What did you see happen?

json: cannot unmarshal string into Go struct field Ticker1.E of type int64

What did you expect to see?

@acczefly
Copy link
Author

Title: json: cannot unmarshal string into Go struct field Ticker.E of type int64

Description:
I have encountered an issue with the encoding/json package in Go, where JSON deserialization does not correctly handle the case sensitivity of fields in strings. Specifically, when deserializing a JSON object, the field names in the JSON string are case-sensitive and do not match the struct fields if there is a difference in case.

@seankhliao
Copy link
Member

Duplicate of #14750

@seankhliao seankhliao marked this as a duplicate of #14750 May 29, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
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