I have the following object
{
value: 20,
color:"#878BB6"
},
{
value : 40,
color : "#4ACAB4"
}
loaded from a text file abc.txt in my local directory in the server.
I want to convert this into an array object. I tried doing
var string = "{
value: 20,
color:"#878BB6"
},
{
value : 40,
color : "#4ACAB4"
}"
var array = JSON.parse("[" + string + "]");
alert(array);
Nothing happens unfortunately. Help appreciated !
var array = JSON.parse("[" + string + "]");JSON.parsewon't work because it's not parsable JSON. You need to ensure that both key/value pairs are quoted appropriately.