I am wracking my brain about this and can't figure out why or how to fix it.
This test should pass:
[Test]
public void EncodingTest()
{
var json = JsonSerializer.Serialize("\"");
Assert.AreEqual("\\\"", json);
}
but it doesn't. It's saying that a double-quote "
in a string should be translated to \"
, which is (fairly universally) the preferred serialization for this character. (See string at json.org.)
But what's actually happening is that it gets encoded as \u0022
which is the unicode code-point for it.
I understand that \u0022
is allowed, but it's horribly unreadable.
I've found this question which pointed me to
- GH issue dotnet/runtime #29879
- GH issue dotnet/runtime #29374
- GH PR dotnet/corefx 39524 which includes a test case to explicitly ensure it encodes this way.
None of what I've read says how to get the JsonSerializer
to just escape it (like every other serializer I've seen).