Pretty print using JSON.stringify()
Syntax: JSON.stringify(value[, replacer[, space]])
where, replacer
is used to apply modifications to the value while stringifying
and space
specifies the indentation of the value.
const obj = {
name: "ABC",
age: 200,
skills: ["C", "JavaScript", "Python"],
};
console.log(JSON.stringify(obj, null, 2));
Prints result as:
{
"name": "test",
"age": 26,
"skills": [
"c",
"javascript",
"php"
]
}