Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting JSON to HTML table in Python

I've been using the JSON library for Python to get data from JSON files using Python.

infoFromJson = json.loads(jsonfile)

I fully understand how to work with JSON files in Python. However, I am trying to find a way to format JSON format in a nice way.

I prefer to convert the JSON into a nested HTML table format.

I found json2html for Python, which does exactly what I just described. However, it does not actually output anything when I run the script they provide.

Has anyone had experience with this tool? Or does anyone have suggestions for alternatives?

like image 549
OMGitzMidgar Avatar asked Jun 23 '15 18:06

OMGitzMidgar


People also ask

Can you convert JSON to HTML?

You can convert your JSON documents from any platform (Windows, Linux, macOS). No registration needed. Just drag and drop your JSON file on upload form, choose the desired output format and click convert button. Once conversion completed you can download your HTML file.

Can we convert JSON to table?

Yes, ImportJSON is a really easy tool to use for taking information from JSON and putting it into a table or spreadsheet. Including if you want to parse your JSON directly from Google Sheets!

Can we convert HTML to JSON in Python?

Python developers can easily load & convert HTML files to JSON in just a few lines of code.


1 Answers

Try the following:

infoFromJson = json.loads(jsonfile)
print(json2html.convert(json = infoFromJson)) 

The result from json2html.convert is a string.

If you don't have json2html module:

$ pip install json2html

More examples here.

like image 73
Kyle Shrader Avatar answered Oct 13 '22 00:10

Kyle Shrader