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: UnmarshalTypeError should tell you what key you were unmarshaling #8254

Closed
kbloom opened this issue Jun 20, 2014 · 5 comments

Comments

Projects
None yet
7 participants
@kbloom
Copy link

commented Jun 20, 2014

As seen at
http://stackoverflow.com/questions/24325210/get-field-name-that-errs-in-go-json-unmarshal,
it would make it easier to debug JSON decoding errors, if UnmarshalTypeError would tell
you which key you were unmarshaling when you encountered the type error.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jun 20, 2014

Comment 1:

Labels changed: added repo-main, release-go1.4.

@gopherbot

This comment has been minimized.

Copy link

commented Jun 21, 2014

Comment 2:

CL https://golang.org/cl/101420043 mentions this issue.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 15, 2014

Comment 3:

Some kind of better reporting would be nice but I don't think this is the right answer.

Labels changed: added release-none, removed release-go1.4.

Status changed to Accepted.

@petemoore

This comment has been minimized.

Copy link

commented Feb 2, 2015

I think it would be helpful here for json.UnmarshalTypeError to have a reference to the full set of bytes that were being unmarshalled, and the character location where the decoding failed. It could even print context lines with an extra line with a ^ character pointing to the problem character:

json: cannot unmarshal #/Person/properties/job/description into Go value of type string.
Failed on line 42 at character 33:
  40     "properties": {
  41         "job": {
  42             "description": 7,
                                ^
  43             "salary": 100000
  45         },
@rjeczalik

This comment has been minimized.

Copy link

commented Feb 2, 2015

@petemoore it's already in master by #9693. Using an offset you can then write your own tool for visualization.

@bradfitz bradfitz closed this Feb 2, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.