I need help creating a custom JavaScript function that will transform an object into a nicely formatted JSON-style string for debugging purposes. My current approach of iterating over object properties does not handle nested objects properly, resulting in [object Object]
being displayed. How can I write a short and simple solution to convert nested objects into multiline strings that can be easily printed to the console?
Unfortunately, the JSON.stringify
function is not available within my iAd Producer environment. Therefore, I am seeking a compact function that I can simply copy and paste.
For instance:
stringify({ data: { hello: 'world', with: { nested: 'objects' } })
The expected output should be:
{
"data": {
"hello": "world",
"with": {
"nested": "objects"
}
}
}