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

kbloom opened this issue Jun 20, 2014 · 5 comments


Copy link

@kbloom kbloom commented Jun 20, 2014

As seen at,
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.
Copy link

@ianlancetaylor ianlancetaylor commented Jun 20, 2014

Comment 1:

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

Copy link

@gopherbot gopherbot commented Jun 21, 2014

Comment 2:

CL mentions this issue.
Copy link

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

Copy link

@petemoore petemoore 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         },
Copy link

@rjeczalik rjeczalik 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants