What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for holding structured data format. JSON is often used to share information over the network in client/server and server/server communications. JSON itself includes no methods or functions; it's just a data storage format. JSON itself has no methods and does not support comments. JSON format came from JavaScript, but it is now actively used in almost all programming languages, including PHP, Python, Java, C++, C#, Go, and most of them, like Python, has built-in modules for working with JSON data.
Why pretty print JSON?
JavaScript objects are typically converted to JSON in a minified format, where all unnecessary characters, such as spaces and newlines, are removed. This reduces the space used when saving JSON to disk and saves bandwidth when transferring JSON over the network. However, such JSON strings are not readable by humans. To make JSON readable, you need to generate a pretty JSON string.
How to pretty print JavaScript object to JSON string?
JavaScript has a built-in JSON.stringify(obj, replacer, space) method to convert objects to JSON and pretty-print the generated JSON string. The third argument, "space," defines the spacing and makes the JSON human-readable:
How to pretty print an existing JSON string?
To pretty print a minified JSON string, you need first to convert it to a JavaScript object and then convert it back to a pretty JSON string.