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: Marshal cant parse chinese punctuation into key #29476

Closed
pwxc opened this issue Dec 31, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@pwxc
Copy link

commented Dec 31, 2018

What did you do?

package main

import (
	"encoding/json"
	"fmt"
)

type JsonTest struct {

	English0 string `json:"English"`
	Chinese0 string `json:"中文"`

	English1 string `json:"English ()"`
	Chinese1 string `json:"中文 ()"`

	English2 string `json:"English ."`
	Chinese2 string `json:"中文 。"`

}

func main() {

	jsonTest := JsonTest{
		English0 : "English",
		Chinese0 : "中文",
		English1 : "English ()",
		Chinese1 : "中文 ()",
		English2 : "English .",
		Chinese2 : "中文 。",
	}


	jsonBytes, _ := json.Marshal(jsonTest)
	fmt.Println(string(jsonBytes))
}

What did you expect to see?

{
"English":"English",
"中文":"中文",
"English ()":"English ()",
"中文 ()":"中文 ()",
"English .":"English .",
"中文 。":"中文 。"
}

What did you see instead?

{
"English":"English",
"中文":"中文",
"English ()":"English ()",
"Chinese1":"中文 ()",
"English .":"English .",
"Chinese2":"中文 。"
}

@pwxc pwxc changed the title encoding/json: Marshal cant parse chinese punctuation encoding/json: Marshal cant parse chinese punctuation into key Dec 31, 2018

@agnivade agnivade added this to the Go1.13 milestone Dec 31, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Dec 31, 2018

@pwxc - Please also mention your go version and go env for completeness.

/cc @mvdan @dsnet

@pwxc

This comment has been minimized.

Copy link
Author

commented Dec 31, 2018

C:\Users\bo>go version
go version go1.10 windows/amd64

C:\Users\bo>go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\bo\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\bo\go
set GORACE=
set GOROOT=D:\Go
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessag
e-length=0 -fdebug-prefix-map=C:\Users\bo\AppData\Local\Temp\go-build609516982=/
tmp/go-build -gno-record-gcc-switches
@mvdan

This comment has been minimized.

Copy link
Member

commented Dec 31, 2018

I'm pretty sure this is a duplicate of #22518. See https://golang.org/src/encoding/json/encode.go#L815 - not all characters are allowed in key/tag strings at the moment. That issue discusses relaxing those constraints - so you can just leave a comment in that issue.

@pwxc

This comment has been minimized.

Copy link
Author

commented Dec 31, 2018

I'm pretty sure this is a duplicate of #22518. See https://golang.org/src/encoding/json/encode.go#L815 - not all characters are allowed in key/tag strings at the moment. That issue discusses relaxing those constraints - so you can just leave a comment in that issue.

Yes, this is a duplicate of #22518. I will leave a comment in that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.