Skip to content

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

Closed as not planned
@acczefly

Description

@acczefly

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.69000000","p":"-77.75000000","q":"19657826.75182800","s":"ETHUSDT","v":"5113.89840000","w":"3844.00025464","x":"3899.69000000"}`

	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?

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