The default behavior of the System.Text.Json JsonSerializer
and Utf8JsonWriter
follows the behavior of JavascriptEncoder.Default
, which means the following character sets are escaped:
- Any non-ascii character
- Characters required escaping based on the JSON RFC
- HTML-specific ascii characters
The current approach involves going through the list of characters, one at a time, and check whether that character needs escaping. We special case the "null" encoder (which is the default when the user doesn't specify their own) and use a 256 byte bit-mask to indicate which character needs to be escaped. https://github.com/dotnet/corefx/blob/52d63157c78c31816b81be1599a5dacf96b5e5ca/src/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Escaping.cs#L82-L109