In node.js, require("util").inspect does something very similar. I could not find the equivalent of a browser, although, fortunately, the node.js implementation is pretty straight forward:
JSON.stringify(value) .replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') ;
In your case, just JSON.stringify(value) should work.
Hope this helps.
source share