json2html, python: json data not converted to html
<p>I'm trying to format json data to html using json2html.
The json data look like this:</p>

<pre><code>json_obj = [{"Agent Status": "status1", "Last backup": "", "hostId": 1234567, "hostfqdn": "test1.example.com", "username": "user1"}, {"Agent Status": "status2", "Last backup": "", "hostId": 2345678, "hostfqdn": "test2.example.com", "username": "user2"}]
</code></pre>

<p>As already reported in post "<a href="http://stackoverflow.com/questions/38633629/json2html-not-a-valid-json-list-python">json2html not a valid json list python</a>", to make the code works, the json parameter must be a dictionary and not a list, so I'm calling it that way:</p>

<pre><code>json_obj_in_html = json2html.convert(json = { "data" : json_obj })
</code></pre>

<p>However it does not format the json data to html only the first level of dictionary { "data" : json_obj }:</p>

<pre><code>print json_obj_in_html
&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;data&lt;/th&gt;&lt;td&gt;[{"Agent Status": "status1", "Last backup": "", "hostId": 1234567, "hostfqdn": "test1.example.com", "username": "user1"}, {"Agent Status": "status2", "Last backup": "", "hostId": 2345678, "hostfqdn": "test2.example.com", "username": "user2"}]&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</code></pre>

<p>Note that the <strong>online</strong> convert tool provides the right output: <a href="http://json2html.varunmalhotra.xyz/" rel="nofollow">http://json2html.varunmalhotra.xyz/</a></p>

<pre><code>&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;data&lt;/th&gt;&lt;td&gt;&lt;ul&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;Agent Status&lt;/th&gt;&lt;td&gt;status1&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Last backup&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;hostId&lt;/th&gt;&lt;td&gt;1234567&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;hostfqdn&lt;/th&gt;&lt;td&gt;test1.example.com&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;username&lt;/th&gt;&lt;td&gt;user1&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;Agent Status&lt;/th&gt;&lt;td&gt;status2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Last backup&lt;/th&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;hostId&lt;/th&gt;&lt;td&gt;2345678&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;hostfqdn&lt;/th&gt;&lt;td&gt;test2.example.com&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;username&lt;/th&gt;&lt;td&gt;user2&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</code></pre>

<p>Any help would be very welcome.</p>

<p>Make sure that <code>json_obj</code> is an array of objects and not a string (<code>str</code>).</p>

<p>I put your code to a complete sample:</p>

<pre><code>from json2html import *
json_obj = [{"Agent Status": "status1", "Last backup": "", "hostId": 1234567, "hostfqdn": "test1.example.com", "username": "user1"}, {"Agent Status": "status2", "Last backup": "", "hostId": 2345678, "hostfqdn": "test2.example.com", "username": "user2"}]
json_obj_in_html = json2html.convert(json = { "data" : json_obj })
print json_obj_in_html
</code></pre>

<p>With <strong>Python 2.7</strong> and <strong>json2html 1.0.1</strong> this leads to this result:
<a href="http://i.stack.imgur.com/Vv5Dy.png" rel="nofollow"><img src="http://i.stack.imgur.com/Vv5Dy.png" alt="enter image description here"></a></p>

<p>If you receive a result like</p>

<pre><code>&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;data&lt;/th&gt;&lt;td&gt;[{"Agent Status": "sta...
</code></pre>

<p>it is very likely that <code>json_obj</code> is a <code>str</code> and not an array of objects. You can check this by inserting a statement like</p>

<pre><code>print type(json_obj)
</code></pre>

<p>before <code>jsonhtml.convert</code>. I assume that <code>type(json_obj)</code> returns a <code>&lt;type 'str'&gt;</code> in your case and that is why the JSON like string appears in your html. To get it right you have to modify your code in that way that <code>type(json_obj)</code> returns <code>&lt;type 'list'&gt;</code>.</p>

python html json json2html