Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 624 Bytes

replacing_newline_jsonstring.md

File metadata and controls

30 lines (22 loc) · 624 Bytes

How to replace \n in a JSON string

When using APIs sometimes you're returned with a JSON string like so:

"something": "hello\n my name is bob and i like to code in\n python

This would print out in HTML as hello my name is bob and i like to code in python where as you want:

hello
my name is bob and i like to code in
python.

To achieve this it's pretty easy as it happens. You just need to add white-space: pre-wrap to your element like so

.new-line {
    white-space: pre-wrap;
}
<div id='description'>
   <p className='new-line'>{route.description}</p>
</div>