Using StringEscapeHandling.EscapeNonAscii with Json.NET

The latest version of Json.NET (4.5.11) contains StringEscapeHandling.EscapeNonAscii, which escapes all non-ASCII characters. But I can’t figure out where to pass it as a parameter.

If I try:
JsonConvert.SerializeObject(myObj, Formatting.Indented, new JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii});

then I get compilation errors:
'Newtonsoft.Json.JsonSerializerSettings' does not contain a definition for 'StringEscapeHandling'

+1
source share
2 answers

Based on the documentation , this property is available only on JsonWriter and its inheritors.

+2
source

In later versions of Newtonsoft.Json, this is available at JsonConvert.SerializeObject by passing an instance of JsonSerializerSettings, where StringEscapeHandling is StringEscapeHandling.EscapeNonAscii.

+1
source

All Articles