Quick and Easy JSON Formatting with Python’s JSON2HTML Library

There are a few Python libraries that have a special place in my heart. Like when I first found out about the XLSX writer library that lets you produce well-formatted Excel spreadsheets with highlighting and all that – I felt bad for how many programs I’d made over the years that just spit out CSV files and left it to the person using it to make them look pretty.

Back when I was with the government, we often had a fast “op-tempo” or “operation tempo”—basically meaning sometimes someone would need something and they’d need it right now. They’d come to my desk asking for something and wouldn’t leave until they had what they wanted. This was before AI, so there were times I’d write some quick Python to pull data from a JSON information feed and need to hand it over immediately.

The problem was, if I just gave them the raw JSON – even though you can open it up in notepad – it’s really ugly to look at and can be hard to figure out what’s going on. That’s when I found out about this Python library called JSON2HTML. It does exactly what it says in the name – takes JSON and saves it down into an HTML file, trying to do a decent job of making it look pretty.

Now, I’m not saying it’s going to create the most well-formatted, best-looking reports you’ve ever seen. But it does a good job of taking JSON and putting it into a format where you can just open it up in a browser and actually view it properly. If you’ve got some JSON that you need to share with other people, or even just look at yourself, and you don’t want to go through the trouble of formatting it for a nicer-looking report, definitely check out the JSON2HTML Python library.

Quick heads up – you’ll need to do a pip install before you can use it, as it’s not something that’s built into standard Python by default.