<p dir="auto">The encoding/json package marshals RawMessage properly or incorrectly as base64 based on whether its container is marshaled by value or as a pointer, which is extremely subtle and trivial to get wrong silently.</p>
<p dir="auto">It also consistently fails to marshal the RawMessage value properly when used as a map value type.</p>
<p dir="auto">Sample code demonstrating these problems:</p>
<p dir="auto"><a href="https://play.golang.org/p/bHuvfyb7qB" rel="nofollow">https://play.golang.org/p/bHuvfyb7qB</a></p>
<pre class="notranslate">The current json.RawMessage implementation defines MarshalJSON on a pointer receiver. 
This causes unexpected behavior when marshalling with non-pointer-receiver objects.

For example:
<a href="http://play.golang.org/p/Cf_6zpIKC0" rel="nofollow">http://play.golang.org/p/Cf_6zpIKC0</a>

Instead, MarshalJSON should be defined on a non-pointer receiver for json.RawMessage. 
This will continue to work for existing code that uses pointer-receivers, but will
change behavior to work "correctly" on code that accidentally uses
non-pointer-receivers.</pre>