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: integer type uintptr not marshalled with "string" option #22629

larhun opened this issue Nov 8, 2017 · 1 comment

encoding/json: integer type uintptr not marshalled with "string" option #22629

larhun opened this issue Nov 8, 2017 · 1 comment


Copy link

@larhun larhun commented Nov 8, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

version 1.9

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?


What did you do?

package main

import (

type A struct {
	X int     `json:",string"`
	Y uintptr `json:",string"`
	Z B

type B map[uintptr]string

func main() {
	s := new(A)
	s.Z = make(B)
	s.Z[0] = ""
	r, _ := json.Marshal(s)

What did you expect to see?


What did you see instead?



As required by the json.Marshal documentation, the Y field of uintptr type, marked with the json tag "string" option, should be marshalled as JSON string, not JSON number.

Please note that the X field, of integer int type, and the map's key of the Z field, of integer uintptr type, are both marshalled as JSON string, as expected by the documentation, that states:

  • The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types.

  • The map's key type must either be a string, an integer type, or implement encoding.TextMarshaler.


At line 1138 of of encoding/json/encode.go, please add reflect.Uintptr to the list of types that can be encoded to JSON string by the "string" option.

@gbbr gbbr changed the title integer type uintptr not marshalled to JSON string with "string" option encoding/json: integer type uintptr not marshalled with "string" option Nov 8, 2017
Copy link

@gopherbot gopherbot commented Nov 8, 2017

Change mentions this issue: encoding/json: permit encoding uintptr as a string

@odeke-em odeke-em added the NeedsFix label Nov 8, 2017
@odeke-em odeke-em added this to the Go1.10 milestone Nov 8, 2017
@gopherbot gopherbot closed this in ed3d672 Nov 8, 2017
@golang golang locked and limited conversation to collaborators Nov 8, 2018
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
3 participants
You can’t perform that action at this time.