Pretty Print JSON in Console
const obj = {
x: 1, y: 2,
data: { test: 'xyz' }
};
console.log(JSON.stringify(obj, null, 2));
JSON.stringify
has two more arguments that allow for pretty printing and processing of the object in question. The second argument is a “replacer” function and the third argument is for indentation. Read more details here.
I am pretty sure I first learned this from this stack overflow post.
I used this technique in yesterdays console hijacking post.