json2html
json2html is a Python wrapper designed to convert JSON objects into human-readable HTML table representations. It provides functionalities to transform nested JSON structures into styled HTML tables. The current version is 1.3.0, and while updates are infrequent, it remains an active and functional library for its intended purpose.
Warnings
- gotcha The 'json' parameter of the `convert` method expects a Python dictionary or list, not a JSON string. If you have a JSON string, you must parse it first using `json.loads()`.
- gotcha By default, HTML tags within text nodes are escaped to prevent Cross-Site Scripting (XSS) attacks. If you intend to render raw HTML content within your JSON values, you must explicitly disable escaping.
- gotcha When a JSON value is an array of objects with identical keys, `json2html` will 'club' them together into a single row by default for a more compact representation. If you need each object in the array to generate a separate row, you must disable this feature.
Install
-
pip install json2html
Imports
- json2html
from json2html import json2html
Quickstart
from json2html import json2html
json_data = {
"name": "Alice",
"details": [
{"age": 30, "city": "New York"},
{"age": 25, "city": "London"}
]
}
html_output = json2html.convert(json=json_data, table_attributes="id=\"info-table\" class=\"table table-bordered\"")
print(html_output)