I've seen multiple of examples of this online, but I've not found anything that helps me solve the problem I'm faced with. I'm trying to convert a JSON object into an HTML table, but I'm faced with a couple of issues.
Suppose I have the following object, call it tableJson
, which is essentially representative of a table with only column headers:
[
{
"firstColumn": []
},
{
"secondColumn": []
},
{
"thirdColumn": []
}
]
In trying to convert this into an HTML table, I have done the following:
jsonDumps = json.dumps(jsonTable)
htmlTable = json2html.convert(json = jsonDumps)
Seems pretty simply. However, the result of htmlTable
gives me two issues:
- The output is in a bullet point list format
- Each column header is treated as a separate table
For example, the result of htmlTable
above is:
<ul>
<li>
<table border="1">
<tr><th>firstColumn</th><td></td></tr>
</table>
</li>
<li>
<table border="1">
<tr><th>secondColumn</th><td></td></tr>
</table>
</li>
<li>
<table border="1">
<tr><th>thirdColumn</th><td></td></tr>
</table>
</li>
</ul>
What is the simply way of creating a table (correctly) so that I don't have it in a bullet point list and so that each column is treated as a correct column rather than a table?
Is there a problem with the way the JSON object is represented? If so, what is the correct syntax so that json2html
converts it correctly into a table?