title: How do I handle newlines in JSON?
body: <p>I've generated some JSON and I'm trying to pull it into an object in JavaScript. I keep getting errors. Here's what I have:</p>
  
  <pre><code>var data = '{"count" : 1, "stack" : "sometext\n\n"}';
  var dataObj = eval('('+data+')');
  </code></pre>
  
  <p>This gives me an error: </p>
  
  <pre><code>unterminated string literal
  </code></pre>
  
  <p>With <code>JSON.parse(data)</code>, I see similar error messages: "<code>Unexpected token ↵</code>" in Chrome, and "<code>unterminated string literal</code>" in Firefox and IE.</p>
  
  <p>When I take out the <code>\n</code> after <code>sometext</code> the error goes away in both cases. I can't seem to figure out why the <code>\n</code> makes <code>eval</code> and <code>JSON.parse</code> fail.  </p>