-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: support int map keys in encoding/json #12529
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
Comments
why not add a MarshalJSON method to your map?
I don't think encoding/json should handle this special case as
it will open up a lot of design questions.
What about map[float64]string and map[complex128]string?
Should encoding/json also handle those? Which string format
should it choose?
|
Related proposal: #12146 |
@minux i experience some troubles moving from python to golang as i use integer keys a lot. The python behavior:
Maybe we can introduce a special method inside json module for marshalling such data? |
I'm speaking about data structures not json
|
This week I added 100+ lines of code to one of our packages to support MarshalJSON and UnmarshalJSON map[int]OurType. I also added 130+ lines of unit tests. While in the standard lib code, I could see it would be far fewer lines based on all of the unexported types and utility functions. I would love to add this to the standard lib. What is the process for getting an issue approved and assigned? |
Did not get to this for Go 1.6, sorry. We should think about this at the same time as #12146. |
@rsc, it seems like #12146 is likely to happen, and there's a CL out at https://golang.org/cl/20356. Given that, you can make your integer keys work but you have to make your own int type with the obvious TextMarshaler/TextUnmarshaler methods. What are your thoughts about also doing this change? I still think it's worth doing, and I'd like to send a 1.7 CL if you agree. |
If the change is small and you can make it happen soon, sure. |
I'll send a CL in the next couple of days. |
CL https://golang.org/cl/22060 mentions this issue. |
Our team faced a strange issue with encoding map[int]string into json. Our current solution is to use patched json encoder, which can encode integer keys as strings.
Why not to implement this in the default module?
The text was updated successfully, but these errors were encountered: