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
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@andrewhodel
Copy link

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

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

@toothrot toothrot added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 22, 2020
@andrewhodel
Copy link
Author

andrewhodel commented Jul 22, 2020 via email

@golang golang locked and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants