I have the following code:
c#
public class Point
{
public string Value { get; set; }
}
var json = JsonSerializer.ToString(new Point { Value = "This is \"first\" point." });
Now json contains the following:
{"Value":"This is \u0022first\u0022 point."}
What is the output you expected, \"? The quotes need to be escaped in some fashion.
Also this appears to be related to or duplicate of dotnet/runtime#29879 and dotnet/runtime#1564.
This is a duplicate of existing issues:
https://github.com/dotnet/corefx/issues/35385
https://github.com/dotnet/corefx/issues/34958
We plan to add the ability for the caller to modify the default behavior by passing in a custom JavaScriptEncoder to JsonWriterOptions, JsonSerializerOptions, and JsonEncodedText.
https://github.com/dotnet/corefx/issues/37192
I never want to use a serializer which escape non-ASCII characters. It's too ugly and slow.
using System;
using System.Text.Json.Serialization;
class X { public string Value { get; set; } }
class Program
{
static void Main()
{
var s = JsonSerializer.ToString(new X { Value = "ใใใใใ" });
Console.WriteLine(s); // {"Value":"\u3042\u3044\u3046\u3048\u304a"}
}
}
๐ to a custom encoder/options.
json is utf-8, this seems like a bug if it's escaping all non-ascii codepoints.
Closing as duplicate.
Most helpful comment
I never want to use a serializer which escape non-ASCII characters. It's too ugly and slow.
๐ to a custom encoder/options.