Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: Enforcement of string-only key type #17188
So, the JSON requirement for string-only dictionary keys is enforced by Go, which is fine. However, Go does not accommodate any custom encoders/decoders that might help the developer get around this. I was trying to investigate where in the JSON code this became an error in order to see if I could quickly throw-together a PR to add this, but I'm having difficulty. For your convenience, this is a walkthrough of the execution path and why it seems I'm getting mixed signals about whether this should actually be a problem.
I'm running on master (>1.7.1), by the way.
If a map needs to be marshaled, and we don't yet have a cached encoder for a map,
So, what's actually complaining and why?
encoding/json also automatically marshals/unmarshals maps with integer-typed keys as well as any type that implements TextMarshaler/TextUnmarshaler.
For even more exotic use cases, you can always implement json.Marshaler/json.Unmarshaler yourself. The output must be valid JSON (e.g., all maps must have string keys).
The fact that you're seeing
This seems more like a question about how to use encoding/json, so I suggest you post to a forum (https://github.com/golang/go/wiki/Questions) instead.
I was looking to understand the mechanics and to potentially extend the package. I don't know if the wiki/forum would be sufficient.
I'm running from AppEngine and I had provided a path with the current version of AppEngine, which I had compiled a few minutes before, without realizing that Go had been built-into the SDK (which makes sense). The SDK isn't yet available with something newer than 1.6.2 and the version in production probably isn't available with anything later yet. On the off-chance that you or someone listening happens to know if there's a newer version in production and how to update the AppEngine SDK to use the newer one (it needs the "goapp" binary) than I'm going to be stuck having to pre-translate my keys.