util.format()
generates '{a:1}'
-style strings which are not valid JSON. (Note that keys are not surrounded by double quotes.) How to convert this kind of strings back into objects?
Use eval
if it's definitely trustworthy:
eval('(' + str + ')');
Unless you have a very good reason not to, you should be using JSON.stringify()
to convert an object to a string and JSON.parse()
to reconstitute an object back from a string.