title: Escape special characters in JSON encoded string
body: <p>I'm using Knockout with MVC and the standard method i've seen to get a view model for knockout is like this:</p>
  
  <pre><code>var model = '@Html.Raw(Json.Encode(Model))';
  var viewModel = ko.mapping.fromJSON(model);
  </code></pre>
  
  <p>But if my model has string properties with special characters in them, e.g. '\r\n' I get a JSON parse error 'unexpected token'.</p>
  
  <p>So I believe I need to escape these characters so they are like '\\r\\n'. How to do this?</p>
  
  <p>I know I can just do this for this particular case:</p>
  
  <pre><code>var model = '@Html.Raw(Json.Encode(Model).Replace(@"\", @"\\"))';
  </code></pre>
  
  <p>but there may be others... tabs, single quotes.</p>
  
  <p>Below is an example of the actual rendered model in the browser:</p>
  
  <pre><code>var model = '{"Id":4465,"TextContents":["EYE FILLET STEAK\r\nLINE 2 IS HERE"]}';
  </code></pre>