Proposal Details
With the possible acceptance of #71497, there are many legacy options added to v1 "encoding/json" to preserve v1 semantics in v2. One such option is EscapeInvalidUTF8
, which is a highly esoteric option to escape the Unicode replacement character in the presence of invalid UTF-8, rather than using the replacement character itself, which is more natural (and what the character exists for).
I propose just changing the default v1 behavior to do the same thing as v2 and delete the EscapeInvalidUTF8
option. I don't really see a particular usefulness to it.
For prior precedence, we have actually changed the low-level formatting of JSON in the past (and pretty substantially so), so this should be an acceptable change that's permitted by the Go compatibility document: * encoding/json: encode \b and \f as '\b' and '\f' in JSON strings * encoding/json: encode \n in strings as "\n", not "\u000A" * encoding/json: encode \t as \t instead of \u0009 * encoding/json: use standard ES6 formatting for numbers during marshal
I don't anticipate any more low-level syntactic changes like these anymore after this last one, since v2 outputs according to RFC 8785 by default (except for guarantees on object ordering).
Comment From: dsnet
\cc @neild
Comment From: neild
SGTM.
Comment From: gopherbot
Change https://go.dev/cl/687116 mentions this issue: encoding/json: remove legacy option to EscapeInvalidUTF8