Black Lives Matter. Please consider donating to Black Girls Code today.

Dash: How to add a newline in string?

I would like to render some json with each bit between {} on its own line like so:

I tried using Markdown’s two spaces as shown below as well as trying to string replace with <br>. Whats the correct way to accomplish adding new lines to a string in Dash?

newstring = '{"Question":"WorkerId","Answer":"123"} {"Question":"HITId","Answer":"456"} {"Question":"Industry","Answer":"789"} '  
newstring = newstring.replace("} {","}   {")

It would be best to put them in separate html.P() elements. I would actually do this:

newstring_list = newstring.split(' ')


app.layout = html.Div([
    for json_entry in newstring_list

But if you’re using actual JSON (i.e., the data actually look like this)


You should just use the JSON library:

import json 

newstring_list = json.loads(newstring)