× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

JSON parse double quotes in string literal

James Jensen
Apr 05, 2015
<p>Remember that you are escaping two string literals: one for declaring the property and one for declaring the variable (<code>lit</code>). So you need to escape your escape character: <code>"test \\"1\\""</code></p> <p></p><div class="snippet"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var lit = '{"foo":"test \\"1\\"","bar":"test 2"}'; console.log(lit); var thaw2 = JSON.parse(lit);</code></pre> </div> </div> <p></p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/29416529/JSON%20parse%20double%20quotes%20in%20string%20literal/29416615">Stack Overflow</a>.</p>
comments powered by Disqus