Replacing escape characters from JSON

I want to replace the "\" character from a JSON string by a empty space. How can I do that?


I have found that the easiest and best way to remove all escape characters from your JSON string, is to pass the string into Regex.Unescape() method. This method returns a new string with no ecapes, even \n \t etc, are removed.

See this MSDN article for more details: Regex.Unescape Method (String) (System.Text.RegularExpressions)


If the json object is a string, in .Net the escape "\" characters are added, should you want to clean up the json string, JObject.Parse({string}) as demonstrated in the following code snippet cleans up nicely:

var myJsonAsString = "{\"Name\": \"John\", \"LastName\": \"Doe\", \"Age\": 199 }";

var myCleanJsonObject = JObject.Parse(myJsonAsString);

Should give us a clean Json object with the escape characters removed.

{
"Name": "John",
"LastName": "Doe",
"Age": 199
}