title: Json.Parse escape newline characters
body: <p>I have a page where I am trying to parse following json string using JSON.parse</p>
  
  <pre><code>'[{"Name":"Eggs","Complete":false,"Notes":"Notes here\n"},{"Name":"Sugar","Complete":false,"Notes":null}]'
  </code></pre>
  
  <p>But following code gives error <code>"Uncaught SyntaxError: Unexpected token"</code></p>
  
  <pre><code>var groceriesJson = JSON.parse(jsonString);
  </code></pre>
  
  <p>Then I came to know that its because of <code>\n</code> in json string. So I did try <a href="https://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascript">this solution</a>. But no luck. Still same error <code>"Uncaught SyntaxError: Unexpected token"</code></p>
  
  <pre><code>function escapeSpecialChars(jsonString) {
  
          return jsonString.replace(/\\n/g, "\\n")
                .replace(/\\'/g, "\\'")
                .replace(/\\"/g, '\\"')
                .replace(/\\&amp;/g, "\\&amp;")
                .replace(/\\r/g, "\\r")
                .replace(/\\t/g, "\\t")
                .replace(/\\b/g, "\\b")
                .replace(/\\f/g, "\\f");
  
        }
  
   var groceriesJson = JSON.parse(escapeSpecialChars(jsonString));
  </code></pre>
  
  <p>Any ideas? Thanks</p>
  
  <p><strong>---UPDATE----</strong></p>
  
  <p>I am not creating this string manually, I have c# codes that creates json string from c# objects </p>
  
  <pre><code> var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
   var groceries = jss.Serialize(Model);
  </code></pre>
  
  <p>then in javascript codes I have </p>
  
  <pre><code>var jsonString = '@Html.Raw(groceries)'
   var groceriesJson = JSON.parse(escapeSpecialChars(jsonString));
  </code></pre>