I know that System.Text.Json escapes single quotes by design, but the examples for how to allow certain characters to not be escaped from MS Docs (https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/character-encoding#serialize-specific-characters)doesn’t work for me as I want to keep single quotes in my serialized JSON.
var encoderSettings = new TextEncoderSettings();
encoderSettings.AllowCharacters('u0027', ''');
encoderSettings.AllowRange(UnicodeRanges.BasicLatin);
var encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(encoderSettings);
var options = new JsonSerializerOptions
{
Encoder = encoder,
};
var bodyJSON = JsonSerializer.Serialize(eventToSend, options);
Is the easy solution to switch to NewtonSoft instead as it is much more user-friendly and by default keeps the single quotes? I have nothing but convoluted trouble and googling for configurations when using System.Text.Json