The third argument of
JSON.stringify(value, replacer, space)
is the number of spaces to use for pretty formatting
let user = {
name: "John",
age: 25,
roles: {
isAdmin: false,
isEditor: true
}
};
document.write('<pre>' + JSON.stringify(user, null, 8) + '</pre>');
It’s fine if we want to send an object over a network.
The
space
argument is used exclusively for a nice output.
Note: max value of space parameter is
20
The result of the above code:
{
"name": "John",
"age": 25,
"roles": {
"isAdmin": false,
"isEditor": true
}
}
It has 8 spaces for each TAB