![]() |
VOOZH | about |
To pretty print JSON, you can format JSON strings with proper indentation, making them easy to read and debug. In JavaScript, you can achieve this using JSON.stringify() with optional parameters to specify the indentation level.
{
"name": "Rahul",
"age": 30,
"city": "Mumbai"
}
1. JSON.stringify() with Indentation
The JSON.stringify() method takes three arguments:
2. Proper Spacing for Readability
By providing an indentation value, you can control the amount of spacing for nested elements.
Syntax
JSON.stringify(value[, replacer[, space]]);{
"name": "Anjali",
"profession": "Developer",
"skills": [
"JavaScript",
"Python"
]
}
When dealing with complex JSON data, pretty printing helps debug issues effectively.
{
"name": "Vikas",
"details": {
"age": 25,
"city": "Delhi"
}
}
Pretty JSON can be written to files for better organization.
You can display formatted JSON in your web app using <pre> tags.