Skip to content

encoding/json: fmt.Print representation of json.RawMessage changed in Go 1.27 #81050

Description

@adamroyjones

Go version

go version go1.27.0 linux/amd64

Output of go env in your module/workspace:

go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/adamroyjones/.local/share/go/bin'
GOCACHE='/home/adamroyjones/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/adamroyjones/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build19368907=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/reprex/go.mod'
GOMODCACHE='/home/adamroyjones/.local/share/go/pkg/mod'
GONOPROXY='github.com/unravelin'
GONOSUMDB='github.com/unravelin'
GOOS='linux'
GOPACKAGESDRIVER=''
GOPATH='/home/adamroyjones/.local/share/go'
GOPRIVATE='github.com/unravelin'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/adamroyjones/.local/share/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27.0.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/adamroyjones/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='go1.27.0'
GOTOOLDIR='/home/adamroyjones/.local/share/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27.0.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.27.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Consider the following program:

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
)

type T struct {
	X json.RawMessage `json:"x"`
	Y []byte          `json:"y"`
}

func main() {
	if err := run(); err != nil {
		panic(err)
	}
}

func run() error {
	j := `{}`
	dec := json.NewDecoder(bytes.NewBufferString(j))

	var t T
	if err := dec.Decode(&t); err != nil {
		return err
	}

	fmt.Printf("%+v\n", t)
	return nil
}

What did you see happen?

$ GOTOOLCHAIN=go1.26.7 go run .
{X:[] Y:[]}

$ GOTOOLCHAIN=go1.27.0 go run .
{X:null Y:[]}

What did you expect to see?

$ GOTOOLCHAIN=go1.26.7 go run .
{X:[] Y:[]}

$ GOTOOLCHAIN=go1.27.0 go run .
{X:[] Y:[]}

I'm not necessarily suggesting that encoding/json ought to change; it is just a minuscule difference between encoding/json before and after the release of Go 1.27 that I thought was worth mentioning.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions