Here is a pull request for my sandbox repository. As the code and test actions, you would easily find the JSON Marshal / Unmarshal functions for json.RawMessage fields behave differently from ones for byte. And the weirdest point is parsing a field of null as the json.RawMessage type results in not nil but the byte array equivalent to a string "null". However, in the cases for other (Go-standard) types, it interprets them as the zero value of the specified type (like 0 for numbers, "" for string, and even nil for byte).
What did you expect to see?
I want the json.RawMessage to behave as possible as similar to byte because it's the type alias, but if this is hard, it's enough that the null value is parsed into nil of json.RawMessage, as above.
What did you see instead?
I'm looking for the implementation code of UnmarshalJSON and MarshalJSON for byte type and want to see the difference from the ones for json.RawMessage, but for now, I couldn't find them. And at least, it's definitely clear this issue can be reproduced on Go Playground: https://play.golang.org/p/YTHmX5FOg_x
The text was updated successfully, but these errors were encountered:
I'm sorry I overlooked that parsing JSON attributes of null returns the different bytes from parsing ones of "null" (Demo). So there is no inconsistency in the system thanks to referential transparency (even though I feel weird that the Unmarshal result doesn't end up a zero value).
Somehow, It was thoughtless of me to marking such a non-critical topic as a GitHub Issue and took your time 🙏