title: JavaScript - Parsing JSON with carriage and new line spaces
body: <p>I am using the following JS code to parse a JSON string from a separate JS file:</p>
  
  <pre><code>// extract JSON from a module's JS
  var jsonMatch = data.match( /\/\*JSON\[\*\/([\s\S]*?)\/\*\]JSON\*\// );
  data = JSON.parse( jsonMatch ? jsonMatch[1] : data );
  </code></pre>
  
  <p>This is an example of the JS file I extract the JSON string from:</p>
  
  <pre><code>JsonString = /*JSON[*/{"entities":[{"type":"EntityPlayer","x":88,"y":138}]}/*]JSON*/;
  </code></pre>
  
  <p>This code works just fine, however if the JS file with the JSON string contains carriage returns and isn't on one complete line then I get a syntax error.</p>
  
  <p>Example:</p>
  
  <pre><code>JsonString = /*JSON[*/{
       "entities":[{
           "type":"EntityPlayer",
           "x":88,
           "y":138}]
       }/*]JSON*/;
  </code></pre>
  
  <p>Returns the following error:</p>
  
  <pre><code>JSON.parse: unexpected non-whitespace character after JSON data
  </code></pre>
  
  <p>Any idea how I could modify my parsing to work by either stripping out whitespace or to remove carriage returns and new line spaces?</p>