Saqib Saqib - 4 months ago 9
JSON Question

How to skip a <br> or any string while parsing json

I have json array object as a result of jquery ajax call.
I have used "< br >" tag in my python code to format my data in DOM. I want to skip this "< br >" tag as I am converting the ajax response json data into pdf file using jspdf and js auto table.
Is there a simple way to skip a set of string ("< br >" in this case) while looping through the json array object.
Here is the one of the object in json array

{"content":{"rows":[["25.07. ","ma","","","","10:44 - 10:51 <br>","10:57","0:00"],["26.07. ","ti","","","","","","0:00"],["27.07. ","ke","","","","","","0:00"],["28.07. ","to","","","","","","0:00"],["29.07. ","pe","","","","","","0:00"],["30.07. ","la","","","","","","0:00"],["31.07. ","su","","","","","","0:00"],["01.08. ","ma","","","","","","0:00"],["02.08. ","ti","","","","","","0:00"],["03.08. ","ke","","","","","","0:00"],["04.08. ","to","","","","","","0:00"],["05.08. ","pe","","","","","","0:00"],["06.08. ","la","","","","","","0:00"],["07.08. ","su","","","","","","0:00"]],"data":[["25.07. ","ma","","","","10:44 - 10:51 <br>","10:57","0:00"],["26.07. ","ti","","","","","","0:00"],["27.07. ","ke","","","","","","0:00"],["28.07. ","to","","","","","","0:00"],["29.07. ","pe","","","","","","0:00"],["30.07. ","la","","","","","","0:00"],["31.07. ","su","","","","","","0:00"],["01.08. ","ma","","","","","","0:00"],["02.08. ","ti","","","","","","0:00"],["03.08. ","ke","","","","","","0:00"],["04.08. ","to","","","","","","0:00"],["05.08. ","pe","","","","","","0:00"],["06.08. ","la","","","","","","0:00"],["07.08. ","su","","","","","","0:00"]],"columns":["Pvm","Päivä","Sisään","Ulos työ","Ulos oma asia","Ulos muu","Ulos","Työaika"]},"title":"peter pan 25.07. - 07.08.2016 0:00"}


enter image description here

Kld Kld
Answer

You can try this

var jsn = {"content":{"rows":[["25.07. ","ma","","","","10:44 - 10:51 <br>","10:57","0:00"],["26.07. ","ti","","","","","","0:00"],["27.07. ","ke","","","","","","0:00"],["28.07. ","to","","","","","","0:00"],["29.07. ","pe","","","","","","0:00"],["30.07. ","la","","","","","","0:00"],["31.07. ","su","","","","","","0:00"],["01.08. ","ma","","","","","","0:00"],["02.08. ","ti","","","","","","0:00"],["03.08. ","ke","","","","","","0:00"],["04.08. ","to","","","","","","0:00"],["05.08. ","pe","","","","","","0:00"],["06.08. ","la","","","","","","0:00"],["07.08. ","su","","","","","","0:00"]],"data":[["25.07. ","ma","","","","10:44 - 10:51 <br>","10:57","0:00"],["26.07. ","ti","","","","","","0:00"],["27.07. ","ke","","","","","","0:00"],["28.07. ","to","","","","","","0:00"],["29.07. ","pe","","","","","","0:00"],["30.07. ","la","","","","","","0:00"],["31.07. ","su","","","","","","0:00"],["01.08. ","ma","","","","","","0:00"],["02.08. ","ti","","","","","","0:00"],["03.08. ","ke","","","","","","0:00"],["04.08. ","to","","","","","","0:00"],["05.08. ","pe","","","","","","0:00"],["06.08. ","la","","","","","","0:00"],["07.08. ","su","","","","","","0:00"]],"columns":["Pvm","Päivä","Sisään","Ulos työ","Ulos oma asia","Ulos muu","Ulos","Työaika"]},"title":"peter pan 25.07. - 07.08.2016 0:00"};

var rows =  jsn.content.rows;
var cleanRows = [];
for(i in rows){
 cleanRows.push(rows[i].map(function(str){ return str.replace('<br>', '' );}))
}
console.log(cleanRows);