Edit: This got marked as already answered, except the linked answer was using JsonSerializer which has a set of serializer options, and I am using Utf8JsonWriter which does not. The answer linked does not solve my problem.
Second Edit: Flydog made an excellent suggestion, thank you. Here is a minimum example in .net6 and output.
using System.Text;
using System.Text.Json;
using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
writer.WriteStartObject();
writer.WritePropertyName("Test");
writer.WriteStringValue("'");
writer.WriteEndObject();
writer.Flush();
File.WriteAllText("Test.json", Encoding.UTF8.GetString(stream.ToArray()));
Output: {"Test":"\u0027"}
I am writing a lot of non-ascii characters to a Utf8JsonWriter backed by a memory stream and it is outputting everything as \uxxxx codes.
Is there a setting somewhere to or is this a deeper issue I am not understanding?
I have also backed it by a FileStream directly and had the same issue. As far as I can tell the json writer is writing the codes directly to bytes.