Looks pretty simple but I am unable to figure it out
var str="[{name:\"House\",id:\"1\"},{name:\"House and Land\",id:\"5\"},{name:\"Land\",id:\"6\"},{name:\"Terrace\",id:\"11\"}]";
JSON.parse(str.replace(/\s/g, "").replace(/\//g, ''));
I am unable to the convert above string(which comes from 3rd party website) to valid json so that I can iterate it on my side
error
VM5304:1 Uncaught SyntaxError: Unexpected token n in JSON at position 2
at JSON.parse (<anonymous>)
console.log( eval( str ) )var string = ...exactly as you have posted?), or is it being returned from some sort of ajax/api call and the slashes appear in your developer tools?JSON.stringify-ied an already valid JSON string (which adds the forward slashes) and now you are trying to parse it - that's what is really going on here.