<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>

This is what you want:
```
```
var data = '{"count" : 1, "stack" : "sometext\\n\\n"}';
```
```
You need to escape the
```
\
```
in your string (turning it into a double-
```
\
```
), otherwise it will become a newline in the JSON source, not the JSON data.