Skip to content

Consider adding a JavaScriptEncoder implementation that doesn't encode the block list or surrogate pairs. #42847

@dan655t

Description

@dan655t

I would like to know if there is a way or any intention for the System.Text.Json serializer to support emojis defined with surrogate pairs?

When we serialize "📲" we get its representation as escaped unicode values. I would like it to remain unescaped.

static void Main()
{
    var encoderSettings = new TextEncoderSettings();
    encoderSettings.AllowRange(UnicodeRanges.All);
    var serializerOptions = new JsonSerializerOptions
    {
        Encoder = JavaScriptEncoder.Create(encoderSettings),
        WriteIndented = true
    };
    var json = JsonSerializer.Serialize("📲", serializerOptions);
    Console.WriteLine(json);
    // "\uD83D\uDCF2"
}

Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions