DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

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));
Enter fullscreen mode Exit fullscreen mode

Prints result as:

{
  "name": "test",
  "age": 26,
  "skills": [
    "c",
    "javascript",
    "php"
  ]
}
Enter fullscreen mode Exit fullscreen mode

Alt Text


Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Discussion (3)

Collapse
bakedbird profile image
Eleftherios Psitopoulos

This is actually pretty cool for when we want to check out responses from an API on a new tab

Collapse
318097 profile image
Mehul Lakhanpal Author

Offcourse 😀

Collapse
bakedbird profile image
Eleftherios Psitopoulos

I just did a video about it. Check it out if you want youtu.be/COwckZNzlNg