How to Pretty Print a JSON File in Python
Like many other programming languages, Python works well with JavaScript Object Notation (JSON) data. It can pull this data in from a few sources and work with it like any other file. This is helpful when you want to pretty print a JSON file in Python.
In this post, we show you how to pretty print a JSON file in two ways. Both will involve using the Terminal and command line, although you may not need Python knowledge at all for one of them.
Need to get started with Python? Try one of these Raspberry Pi kits!
What Pretty Print Is (And Why You’d Want to Use It With JSON Files)
In short, pretty printing takes data in a raw format and alters it to something readable. In other words, it makes it pretty.
Under usual circumstances, you’ll do this with files pulled into your program that need to be parsed by a human. Often, data from other file formats (such as JSON files) will have been “minified.” This strips away all of the white space from the code in order to make it leaner for a computer to parse.
For example, you could take raw database data that’s been minified and run it through a script to add the correct indentation and other formatting. From there, you can export it to others and work with it as you wish.
Read more: How to Pretty Print a JSON File in Python