Extract JSON from HTML <script> tag with JavaScript
<p>A web page has JSON inside its html tree within script tag. I need to extract that JSON object and manipulate with it as JSON object. Please advice how can I achieve it.
I am trying to do it in such way:</p>

<pre><code>var url = 'https://indooroopillyshopping.com.au/stores/'
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
console.log("sending request to ", url);
//WAIT
xhr.send();
console.log("receive respond from ", url);

var data = xhr.responseText;
var json = data.match(/\[{"id":"836","title":"Acutherapy".*/g); //I need an object window.STORES = [{}]
var parsedJson = JSON.parse(stringJson);//catch an error
</code></pre>

<p>I also tried to do in such way:</p>

<pre><code>var json = data.match(/{"id":"836","title":"Acutherapy".*/g);
var newjson = json[0].substring(0, json[0].length-2);//remove space and square bracket at the end
var stringJson = JSON.stringify(newjson);
var parsedJson = JSON.parse(stringJson)
console.log(parsedJson[0].id)//I cannot access JSON with dot notation as it acts like a string (object but not [Object object])
</code></pre>

<p>All I need is to convert json string to json object to have access to it's keys and values.</p>