title: Json.NET SerializeObject escape values to prevent XSS
body: <p>Using Json.NET</p>
  
  <pre><code>JsonConvert.SerializeObject(new { Property = "&lt;script&gt;alert('o hai');&lt;/script&gt;" })
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>{"Property":"&lt;script&gt;alert('o hai');&lt;/script&gt;"}
  </code></pre>
  
  <p>Is it possible for the value to be escaped by SerializeObject to prevent a hostile script from executing? I'd prefer not to make changes to the object itself.</p>
  
  <p>Edit: Ideally I'd like to integrate the sanitizing into the SerializeObject call without having to process the object before or after SerializeObject.</p>
  
  <p>Edit: The string output from <code>JsonConvert.SerializeObject</code> is assigned to a global variable in a script block, which I believe is where the XSS issue is.</p>