Json response containing – (en dash) returned as –

I can’t get rid of the – in my JSON response. It should be returning a – (en dash) character.

I’ve tried using:
JsConfig.EscapeUnicode = true;

But it didn’t make a difference.

Please help.


Can you provide an example of this, e.g. sample code using the serializer and the actual JSON response it generates.

I’ve just included the json section that has the issue as the other information is sensitive. The title property has the issue.

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Vary: Accept
Server: Kestrel
Set-Cookie: ss-id=015kdDsYCDhpKFWvFOwd; path=/; samesite=lax; httponly
Set-Cookie: ss-pid=32CetCyL6TRAfIVdz2BG; expires=Mon, 05 Apr 2038 18:43:05 GMT; path=/; samesite=lax; httponly
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type, Allow, Authorization, X-Args, authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
Access-Control-Allow-Origin: http://localhost:8080
X-Powered-By: ServiceStack/5.02 NETStandard/.NET
X-SourceFiles: =?UTF-8?B?RDpcV1dXXHMzYi1hcGlcQ0I0LlMzQi5TZXJ2aWNlc1xzZWFyY2hccG9saWN5?=
X-Powered-By: ASP.NET
Date: Thu, 05 Apr 2018 18:43:08 GMT

{"__type":“CB4.S3B.Services.Modules.Policy.Data.PolicyStatus, CB4.S
3B.Services”,“id”:“100”,“title”:“InActive \u00EF\u00BF\u00BD S3B”,“description”:"",“activeType”:false,“persistencyGroup”:“3”,“toArrears”:false},“agent1Splits”:100,“agent2Splits”:0,“agent3Splits”:0,“agent4Splits”:0}

The issue is missing important context, like where exactly are you seeing the non-printable character? and what exactly is getting encoded as JSON. Is the issue meant to be in the JSON response because I’m not seeing it?

The JSON serializer encodes ‘–’ correctly, which is a valid UTF-8 character.

I’ve created a live example of a DTO with the en dash character in it on gistlyn.

class Dto
    public string Text { get; set; }       

var dto = new Dto { Text = "The – (en dash) character" };

var json = dto.ToJson();


Which prints out:

{"Text":"The – (en dash) character"}

Which is exactly what the browsers JSON API serializes:

console.log(JSON.stringify({ Text: "The – (en dash) character" }))

Which also prints:

{"Text":"The – (en dash) character"}

If you’re viewing this in a HTML browser you may want to HTML Encode the contents. The HTML Entity for the EN DASH character is – or –. If this is in a web page make sure it includes the meta UTF-8 charset.

I do have the meta tag set as above.

See a screenshot of the DevTools Console

This is the same as it looks on the website as well.

Please read my answer carefully, the en dash character is being serialized correctly. You may want to HTML Encode it if you’re displaying the response in a web page. The HTML Entity for the EN DASH character is – or –.