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: add the full path to the field in UnmarshalTypeError #22369

Open
Splik opened this Issue Oct 20, 2017 · 2 comments

Comments

Projects
None yet
5 participants
@Splik

Splik commented Oct 20, 2017

go1.9.1 linux/amd64

I parse some JSON with nested objects on the server, and I cannot find the actual path to a nested field in UnmarshalTypeError. An example below.

Body payload:

{
	"Child": {
		"Field": "string" <--- here's the  invalid type
	}
}
type ParentStruct struct {
  Child ChildStruct
}

type ChildStruct struct {
  Field int
}

d := Parent{}

decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&d)

What I expect to see

s

What I see instead

s

Such field like Path may be used to render detailed errors for some REST API.

@mvdan mvdan changed the title from encoding/json add the actual path to the field to UnmarshalTypeError to encoding/json: add the full path to the field in UnmarshalTypeError Oct 20, 2017

@mvdan mvdan added the Suggested label Oct 20, 2017

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 20, 2017

@gopherbot

This comment has been minimized.

gopherbot commented Oct 27, 2018

Change https://golang.org/cl/145218 mentions this issue: encoding/json: add Path to UnmarshalTypeError

@Gnouc

This comment has been minimized.

Contributor

Gnouc commented Nov 6, 2018

@mvdan Can you take a look at newest change?

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