We all know we can use JSON.parse() to convert the string \'{\"a\":0,\"b\":\"haha\"}\' to the object {a: 0, b: \'haha\'}.
JSON.parse()
\'{\"a\":0,\"b\":\"haha\"}\'
{a: 0, b: \'haha\'}
But can
Something like this might work:
function evalJsString(str) { let a = null; try { eval('a = ' + str); } catch (err) { console.error(err); } if(typeof a === "object") return a; else return null; } evalJsString('({a: 0, b: "haha"})');