We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
null
"null"
go version
$ go version go version go1.13.1 linux/amd64
i can reproduce on go version go1.14 linux/amd64
go version go1.14 linux/amd64
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/oha/.cache/go-build" GOENV="/home/oha/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/oha/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/oha/sdk/go1.13.1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/oha/sdk/go1.13.1/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build838880304=/tmp/go-build -gno-record-gcc-switches"
package main import ( "encoding/json" "testing" ) type Frame struct { Data json.RawMessage `json:"data"` } func TestJson(t *testing.T) { f := Frame{Data: nil} t.Logf("%#v (%q)", f, f.Data) j, _ := json.Marshal(f) t.Logf("json: %s", j) var f2 Frame json.Unmarshal(j, &f2) t.Logf("%#v (%q)", f2, f2.Data) }
f.Data and f2.Data should be the same (nil)
f.Data
f2.Data
=== RUN TestJson --- PASS: TestJson (0.00s) json_test.go:14: main.Frame{Data:json.RawMessage(nil)} ("") json_test.go:17: json: {"data":null} json_test.go:21: main.Frame{Data:json.RawMessage{0x6e, 0x75, 0x6c, 0x6c}} ("null") PASS
json.Unmarshal decode null as "null"
The text was updated successfully, but these errors were encountered:
note, if json:"data,omitempty" than everything works as expected
json:"data,omitempty"
Sorry, something went wrong.
I think you're just seeing the result of using the %q format which quotes things. Maybe you meant to use %s.
%q
%s
i included also the %#v which shows how json.RawMessage(nil) is turned into json.RawMessage{0x6e, 0x75, 0x6c, 0x6c} which are the ascii of null
json.RawMessage(nil)
json.RawMessage{0x6e, 0x75, 0x6c, 0x6c}
I believe this is working as intended, json.RawMessage specifically means not to parse the data and store it as is in json
json.RawMessage
oh yes, i see it now. if further Unmarshalled, it returns nil.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
i can reproduce on
go version go1.14 linux/amd64
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
f.Data
andf2.Data
should be the same (nil)What did you see instead?
json.Unmarshal decode
null
as"null"
The text was updated successfully, but these errors were encountered: