title: Encode umlauts in JSON.NET
body: <p>Is it possible to encode strings with umlauts in JSON.NET that the serialized string is encoded like this?</p>
  
  <p>"Pläne" => "Pl\u00e4ne"</p>
  
  <p><strong>Update:</strong>
  After sra anwser I came up with the following code that worked for me. </p>
  
  <pre><code>public class Utf8Converter : JsonConverter
      {
          public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
          {
              string s = (string)value;
              s = EncodeNonAsciiCharacters(s);            
              writer.WriteValue(s);
          }
  
          public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                          JsonSerializer serializer)
          {
              throw new NotImplementedException();
          }
  
          public override bool CanConvert(Type objectType)
          {
              return typeof(string).IsAssignableFrom(objectType);
          }
  
  
          private static string EncodeNonAsciiCharacters(string value)
          {
              StringBuilder sb = new StringBuilder();
              foreach (char c in value)
              {
                  if (c == '\t')
                      sb.Append(@"\t");
                  else if (c == '\n')
                      sb.Append(@"\n");
                  else if (c == '\r')
                      sb.Append(@"\r");
                  else if (c &gt; 127)
                  {
  
                      string encodedValue = @"\u" + ((int)c).ToString("x4");
                      sb.Append(encodedValue);
                  }
                  else
                  {
                      sb.Append(c);
                  }
              }
              return sb.ToString();
          }
  
  
  
      }
  </code></pre>