proposal: encoding/json: allow unmarshaling singleton into slice #19854
Labels
Milestone
Comments
If it's common I'm a little surprised it hasn't come up already. Can you point to specific JSON implementations that don't care and are causing problems? I mean, JavaScript clearly distinguishes between [1] and 1 for example. |
Ping. Any new context here? I'm still skeptical this is a common problem. |
Closing for lack of motivation. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It's common for dynamic languages to be somewhat lax about the distinction
between an array and a single value when encoding and decoding JSON.
For example, a single value may be generated where an array is also acceptable.
Currently this can be worked around by defining a special type
for the slice being unmarshaled to.
For example:
This is cumbersome. Instead we could make encoding/json automatically
allow a singleton value when decoding into a slice, or provide an
struct tag option to enable that behaviour.
The text was updated successfully, but these errors were encountered: