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: doesn't deserialize json fields with underscores into struct's fields who's tag contains the underscore but the struct field name does not #40351

andrewhodel opened this issue Jul 22, 2020 · 2 comments


Copy link

@andrewhodel andrewhodel commented Jul 22, 2020

This issue - #9841

Is true for go1.14.2

This works

Ws_Id              string.   `json:"ws_id"`

This does not work

WsId              string.   `json:"ws_id"`

Is it fixed in a later version or has all new manufacturing stopped LOL.

Copy link

@toothrot toothrot commented Jul 22, 2020

@andrewhodel Could you please provide an example of your issue? The following code works well for me:

package main

import (

type Foo struct {
	Ws_Id string `json:"ws_id"`

type Bar struct {
	WsId string `json:"ws_id"`

func main() {
	js := []byte(`{"ws_id": "abc"}`)

	var f Foo
	var b Bar
	json.Unmarshal(js, &f)
	json.Unmarshal(js, &b)
	fmt.Printf("f: %+v\n", f)
	fmt.Printf("b: %+v\n", b)


$ go1.14.2 run main.go 
f: {Ws_Id:abc}
b: {WsId:abc}

Alternatively, see the playground:

I'm not sure I understand the comment about manufacturing.

Copy link

@andrewhodel andrewhodel commented Jul 22, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants