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

Splik opened this Issue Oct 20, 2017 · 2 comments


None yet
5 participants

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


What I see instead


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


This comment has been minimized.

gopherbot commented Oct 27, 2018

Change mentions this issue: encoding/json: add Path to UnmarshalTypeError


This comment has been minimized.


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