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: Unmarshal to nil pointer documentation discrepancy #18730
When trying to unmarshal a json string into a nil pointer, the operation fails as can be seen here:
The error returned is InvalidUnmarshalError whose docs clearly state:
But the docs for the Unmarshal function state:
Obviously, the behaviour implemented is the one from the error docs.
Curiously, this works:
My understanding is that this is a documentation bug. The behavior of returning an InvalidUnmarshalError looks work-as-intended. I guess the docs for the Unmarshal function means "If the pointer points to nil"? Because Unmarshal cannot modify the passed nil pointer.