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

Closed
andrewhodel opened this issue Jul 22, 2020 · 2 comments

Comments

@andrewhodel
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.

@toothrot
Copy link
Contributor

@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 (
	"encoding/json"
	"fmt"
)

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)
}

Output:

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

Alternatively, see the playground:
https://play.golang.org/p/LWtwMGPSGtC

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

@andrewhodel
Copy link
Author

@andrewhodel andrewhodel commented Jul 22, 2020

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.