0

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.

dbc
  • 91,441
  • 18
  • 186
  • 284
timelost
  • 1
  • 1
  • If the linked question doesn't answer your question, re-read the linked question. Notice that it shows some code, some input and some output - completing the requirements for a [mcve]. When you have all that, people can read your question, try it out and say "Oh, you just need to connect the carburetor to the door handle". Your question, as written, doesn't really allow someone who isn't on your team to understand your problem very well – Flydog57 Apr 13 '22 at 19:52

0 Answers0