title: JS - Parsing JSON with html
body: <p>I have data in this format:</p>
  
  <pre><code>var data = "{"attr":"value","html":"&lt;div&gt;&lt;div style="left: 0px;"&gt;&lt;/div&gt;&lt;/div&gt;"}";
  </code></pre>
  
  <p>There is more to the html, but its not required here. I try to do:</p>
  
  <pre><code>data = JSON.parse(data)
  </code></pre>
  
  <p>This errors giving:</p>
  
  <blockquote>
    <p>Uncaught SyntaxError: Unexpected token l</p>
  </blockquote>
  
  <p>Due to the additional " in the style. How do you correctly parse this?</p>
  
  <p>edit:</p>
  
  <p>I am getting data from a server, so I receive it in a websocket such as:</p>
  
  <pre><code>sock.onmessage = function(message) {
      //Need to parse this.
      data = message.data
  
      console.log(typeof data); // = string
      console.log(data);
      //console.log(data) result        
      //{"attr":"value","html":"&lt;div&gt;&lt;div style="left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;"&gt;Content&lt;/div&gt;&lt;/div&gt;"}
  }
  </code></pre>