convert json to html with Python [closed]

I've understood the method used in post How can I render an html from a JSON-like string?

I guess I can use a for loop to create a bunch of elements as well as go through each of them, setting attributes and textContent.

This code snippet

f1=open('./notes.html', 'a')
num_attributes = 0
num_insert = 0
for i in json_arr:
if len(i) == 2:
attr_color = i['attributes']['color']
content = '<p><span style="color:' + attr_color + ';">'+i['insert']+'</span></p>'
else:
content = '<p><br></p>'
f1.write(content + "\n")
f1.close()


is to convert the following json (click here to get the complete list)

[{'attributes': {'color': '#ff0084'},
'insert': 'Hello everyone, welcome to class..'},
{'insert': '\n\n\n'},
{'attributes': {'color': '#dc4d50'}, 'insert': '-I often go walk.'}]


to an html.

<p><span style="color:#ff0084;">Hello everyone, welcome to class..</span></p><p><br></p><p><span style="color:#dc4d50;">-I often go walk.</span></p><p><br></p><p><span style="color:#20b69d;">-I often go for a walk.</span></p><p><br></p><p><span style="color:#20b69d;">-I often take a walk.</span></p><p><br></p><p><span style="color:#dc4d50;">-I often go eat out.</span></p><p><br></p><p><span style="color:#20b69d;">-I often eat out.</span></p><p><br></p><p><span style="color:#dc4d50;">-Not usual meet my coworks after work.</span></p><p><br></p><p><span style="color:#20b69d;">-I hardly{Rarely} meet my coworkers after work.</span></p><p><br></p><p><span style="color:#dc4d50;">-We usually eating out together.</span></p><p><br></p><p><span style="color:#20b69d;">-We usually eat out together.</span></p><p><br></p><p><span style="color:#dc4d50;">-The feel is relaxing.</span></p><p><br></p><p><span style="color:#20b69d;">-The feeling is relaxing.</span></p><p><br></p><p><span style="color:#dc4d50;">-What do we need take with us?</span></p><p><br></p><p><span style="color:#20b69d;">-What do we need </span></p><p><span style="color:#424242;">to</span></p><p><span style="color:#20b69d;"> take with us?</span></p><p><br></p><p><span style="color:#dc4d50;">-We don't swimming.</span></p><p><br></p><p><span style="color:#20b69d;">-We don't swim.</span></p><p><br></p><p><span style="color:#20b69d;">-We won't be swimming.</span></p><p><br></p><p><span style="color:#dc4d50;">-We need to food.</span></p><p><br></p><p><span style="color:#20b69d;">-We need to take some food.</span></p><p><br></p><p><span style="color:#dc4d50;">-Anything activity?</span></p><p><br></p><p><span style="color:#20b69d;">-Are we going to be doing any activities?</span></p><p><br></p><p><span style="color:#dc4d50;">-We don't need to take tent.</span></p><p><br></p><p><span style="color:#20b69d;">-We don't need to take a tent.</span></p><p><br></p><p><span style="color:#20b69d;">-We don't need to take tents.</span></p><p><br></p><p><span style="color:#9952fd;">-We need to take some sun lotion.</span></p><p><br></p><p><span style="color:#9952fd;">-We don't need to take boots.</span></p><p><br></p>

The code works the way as expected. I'd just like to know whether my code is Pythonic. If not, how do I improve it?

• Does it work the way it should? – Mast Jul 25 at 13:40
• @Mast The code works the way as expected. I'd just like to know whether my code is Pythoneer. If not, how do I improve it. – JJJohn Jul 25 at 15:08
• Missing Review Context: Code Review requires concrete code from a project, with enough code and / or context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site. This is the closure category since you describe this as a snippet. We need to see the full code. – Reinderien Jul 26 at 2:33