encoding/json: strange isEmptyValue behavior with arrays #31189
Closed
Labels
Comments
I believe the behavior you're seeing is correct.
A zero-length array is empty:
would have the desired output you expect, however having a zero-length array is likely not what you'd want. I would use slices instead if that works for your use-case. Changing this behavior would break people who rely on the current encoding semantics with arrays, so it's likely not going to happen. |
Thank You for the answer, since some people rely on the current implementation, now I am sure it is okay to have a separate package. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using?
Does this issue reproduce with the latest release?
Yes, it does.
What operating system and processor architecture are you using?
go env
OutputWhat did you do?
https://play.golang.org/p/JTZn-qSksgw
What did you expect to see?
What did you see instead?
Possible solution
Is this behavior is correct? If no:
In
encoding/json
theencode.go
file contains:Since that, any array will never be empty.
Used to fork the package and change it to:
The text was updated successfully, but these errors were encountered: